A + B Problem II(1002)
first line of the input contains an integer T(1<=T<=20) which
means the number of test cases. Then T lines follow, each line consists
of two positive integers, A and B. Notice that the integers are very
large, that means you should not process them by using 32-bit integer.
You may assume the length of each integer will not exceed 1000.
each test case, you should output two lines. The first line is "Case
#:", # means the number of the test case. The second line is the an
equation "A + B = Sum", Sum means the result of A + B. Note there are
some spaces int the equation. Output a blank line between two test
cases.
1 2
112233445566778899 998877665544332211
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; int main()
{
int n , ans = ;
cin >> n ;
while(n --)
{
ans++ ;
char a[] = {}, b[] ={} ;
int c[] ={}, d[] = {} , e[] ={};
scanf("%s%s" , &a , &b);
int len1 = strlen(a) ;
int len2 = strlen(b) ;
int len = max(len1 , len2);
int j = ;
for(int i = len1 - ; i >= ; i--)
{
c[j++] = a[i] - ;
}
j = ;
for(int i = len2 - ; i >= ; i--)
{
d[j++] = b[i] - ;
}
int k = ;
for(int i = ; i < len ; i++)
{
e[i] = (c[i] + d[i] + k) % ;
k = (c[i] + d[i] + k) / ;
}
cout << "Case " << ans << ':' << endl ;
printf("%s + %s = " , a , b);
if(!k)
{
for(int i = len - ; i >= ; i--)
cout << e[i] ;
cout << endl ;
}
else
{
e[len] = k ;
for(int i = len ; i >= ; i--)
cout << e[i] ;
cout << endl ;
}
if(n != )
printf("\n"); }
return ;
}
A + B Problem II(1002)的更多相关文章
- nyoj 623 A*B Problem II(矩阵)
A*B Problem II 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...
- hdu 1002 A + B Problem II(大数)
题意:就是求a+b (a,b都不超过1000位) 思路:用数组存储 第一道大数的题目,虽然很水,纪念一下! 代码: #include<cstdio> #include<cstring ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- 【BZOJ2998】Problem A(动态规划)
[BZOJ2998]Problem A(动态规划) 题面 BZOJ 题解 一个人的成绩范围可以确定为一个区间 这样就变成了 选择若干区间,不重合, 每个区间有个权值,求最大权值和 这样就可直接\(dp ...
- 【Luogu1414】又是毕业季II(数论)
[Luogu1414]又是毕业季II(数论) 题面 题目背景 "叮铃铃铃",随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘 ...
- 【BZOJ2302】[HAOI2011]Problem C(动态规划)
[BZOJ2302][HAOI2011]Problem C(动态规划) 题面 BZOJ 洛谷 题解 首先如果\(m=0\)即没有特殊限制的话,那么就和这道题目基本上是一样的. 然而这题也有属于这题的性 ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU 1002:A + B Problem II(大数相加)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- A + B Problem II(杭电1002)
/*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...
随机推荐
- SDOI2010代码拍卖会 (计数类DP)
P2481 SDOI2010代码拍卖会 $ solution: $ 这道题调了好久好久,久到都要放弃了.洛谷的第五个点是真的强,简简单单一个1,调了快4个小时! 这道题第一眼怎么都是数位DP,奈何数据 ...
- 数据库JDBC
数据库概述 什么是数据库?数据库就是存储数据的仓库,本质是一个文件系统,数据按照特定的格式将数据存储起来,用户可以通过SQL对数据库进行增删改查操作. 数据库对应一个应用系统,在系统中有很多的功能,每 ...
- Android PdfViewer案例使用
今天按项目要求找了一个android的PDF控件,各种操作效果都非常好,在这里和大家分享一下. com.joanzapata.pdfview:android-pdfview 该PDF控件加载大存储的 ...
- JavaSE---显式锁
1.概述 1.1.jdk5之前,用于 调节共享对象访问机制 只有 synchronized.volatile: jdk5之后,提供了 显示锁:Lock.ReentrantLock...: ...
- Extjs中如何在一行textfield后面增加文字提示
添加监听事件: listeners: { render: function(obj) { var font=document.cre ...
- linux运维、架构之路-KVM虚拟化技术
一.云计算概述 云计算:是一种资源使用和交付模式 虚拟化:一种具体的技术,用来将物理机虚拟成为多个相互独立的虚拟机.云计算不等于虚拟化,云计算是使用了虚拟化的技术做支撑 二.KVM配置使用 1.系统环 ...
- JS——数组中push对象,覆盖问题,每次都创建一个新的对象
今天写运动框架时,发现将对象push进数组,后面的值会覆盖前面的值,最后输出的都是最后一次的值.其实这一切都是引用数据类型惹的祸. 如果你也有类似问题,可以继续看下去哦. 下面 ...
- HTML5基础知识汇总(一)
一.HTML的开发工具和使用的浏览器 开发工具:记事本等文本编辑器,Atom.VisualStudioCode( VSCode).Brackets.Sublime text和Hbuider. 浏览器: ...
- 【PowerOJ1738&网络流24题】最小路径覆盖问题 (最大流)
题意: 思路: [问题分析] 有向无环图最小路径覆盖,可以转化成二分图最大匹配问题,从而用最大流解决. [建模方法] 构造二分图,把原图每个顶点i拆分成二分图X,Y集合中的两个顶点Xi和Yi.对于原图 ...
- dispatch_sync 与 dispatch_barrier_sync 区别
最后更新:2017-12-12 dispatch_sync 与 dispatch_barrier_sync https://github.com/rs/SDWebImage/pull/818 The ...