I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. 

Input

The 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.

Output

For 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.

Sample Input

2
1 2
112233445566778899 998877665544332211

Sample Output

Case 1:
1 + 2 = 3 Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110 // too young and didn't notice that
// "you should not process them by using 32-bit integer"
// and "Output a blank line between two test cases".
 #include<stdio.h>
int main()
{
int a, b, t, i;
scanf("%d", &t);
for(i=;i<=t;i++)
{
scanf("%d %d", &a, &b);
printf("Case %d:\n", i);
printf("%d + %d = %d\n", a, b, a+b);
printf("\n");
}
return ;
}

Wrong Answer

// long int is also 32-bit integer.
代码省略
// 不用判断哪个数较长,只要记录答案的长度. 三个数组都要初始化为0!!!
 #include<stdio.h>
#include<string.h> int reverse_add(int *a, int *b, int *c, int al, int bl)
{
int i, sum=, k, max;
if(al<bl) max=bl;
else max=al;
k=;
for(i=; i<max; i++)
{
*(c+i)=(*(a+i)+*(b+i)+k)%;
k=(*(a+i)+*(b+i)+k)/;
}
if(k!=)
{
*(c+i)=;
return max+;
}
else return max;
} int main()
{
char s1[], s2[];
int t, k, i, length_a, length_b, rmax;
scanf("%d", &t);
for(k=;k<=t;k++)
{
int a[]={}, b[]={}, c[]={}; /* 三个数组都要初始化 */
scanf("%s %s", s1, s2);
length_a=strlen(s1); length_b=strlen(s2);
for(i=; i<length_a; i++) a[i]=s1[length_a--i]-'';
for(i=; i<length_b; i++) b[i]=s2[length_b--i]-'';
rmax=reverse_add(a, b, c, length_a, length_b);
printf("Case %d:\n", k);
printf("%s + %s = ", s1, s2);
for(i=; i<rmax; i++) printf("%d", c[rmax--i]);
printf("\n");
if(t>&&k<t) printf("\n");
}
return ;
}

AC

 

1C - A + B Problem II的更多相关文章

  1. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  2. nyoj 623 A*B Problem II(矩阵)

    A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...

  3. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  4. A + B Problem II

    之前总是在查阅别人的文档,看着其他人的博客,自己心里总有一份冲动,想记录一下自己学习的经历.学习算法有一段时间了,于是想从算法开始自己的博客生涯O(∩_∩)O~~ 今天在网上看了一道大数相加(高精度) ...

  5. nyoj 103 A + B problem II

    点击打开链接 A+B Problem II 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. G ...

  6. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  7. HDU1002 -A + B Problem II(大数a+b)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  9. hdoj 1002 A + B Problem II

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 10.mysql-触发器.md

    目录 定义 语法 定义 当操作了某张表时,希望同时触发一些动作/行为,可以使用触发器完成 语法 -- 需求: 当向员工表插入一条记录时,希望mysql自动同时往日志表插入数据 -- 创建触发器(添加) ...

  2. C++ 关于MFC List Control 控件的使用事项 原创

    1\在开发项目时,使用到了 listcontrol 控件,就一些问题,做一下备注,以备以后使用 (1)  给list项目 删除所有的项目  DeleteAllItems(); (2) 给list项目 ...

  3. sse实例

    一.前台 <script>//D:\wamp\www\node\xiangmuer\views\main // var source = new EventSource('http://1 ...

  4. CentOS7下解决yum install mysql-server没有可用包

    # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm --  http://repo.mysql.com/mysq ...

  5. Bootstrap 代码

    [Bootstrap 代码] Bootstrap 允许您以两种方式显示代码: 第一种是 <code> 标签.如果您想要内联显示代码,那么您应该使用 <code> 标签. 第二种 ...

  6. python远程操作服务器

    python远程控制 标签(空格分隔): 远程Linux python远程控制:方案: Paramiko Pexpect(主要Linux机器) 安装Paramiko pip install param ...

  7. 使用fckeditor上传多张图片

    流程: 1.使用fck上传图片到后台 2.后台上传图片到服务器端 3.服务器端返回上传信息 1.jsp页面 <script type="text/javascript"> ...

  8. springboot org.hibernate.MappingException: No Dialect mapping for JDBC type: -9

    参考 https://www.cnblogs.com/luxd/p/8316243.html https://www.cnblogs.com/s648667069/p/6478559.html @Co ...

  9. 【selenium+python】关于使用selenium时的几个问题1

    问题:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in ...

  10. Forms.WebBrowser与Controls.WebBrowser区别

    Forms.WebBrowser与Controls.WebBrowser区别 Forms.WebBrowser有ScrollBarsEnabled 属性,即窗口滚动条,可以设置为false即可: Co ...