A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 260585    Accepted Submission(s): 50389

Problem Description
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
#include<stdio.h>
#include<string.h>
#define MAX 1100
char str1[MAX],str2[MAX];
int a[MAX],b[MAX];
int main()
{
int n,m,j,i,s,t,l1,l2,k,ok;
scanf("%d",&t);
k=1;
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%s%s",str1,str2);
l1=strlen(str1);
l2=strlen(str2);
for(i=l1-1,j=0;i>=0;i--)
{
a[j]=str1[i]-'0';
j++;
}
for(i=l2-1,j=0;i>=0;i--)
{
b[j]=str2[i]-'0';
j++;
}
n=0;
if(l1<l2)
{
n=l1;
l1=l2;
l2=n;
}
for(i=0;i<l1;i++)
{
a[i]=a[i]+b[i];
if(a[i]>=10)
{
a[i]-=10;
a[i+1]++;
}
}
ok=0;
if(a[l1]>0)
{
ok=1;
}
printf("Case %d:\n",k++);
printf("%s + %s = ",str1,str2);
if(!ok)
for(i=l1-1;i>=0;i--)
printf("%d",a[i]);
else
for(i=l1;i>=0;i--)
printf("%d",a[i]);
printf("\n");
if(t)
printf("\n");
}
return 0;
}

hdoj 1002 A + B Problem II【大数加法】的更多相关文章

  1. HDU 1002 A + B Problem II(高精度加法(C++/Java))

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

  2. hdoj 1002 A + B Problem II

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

  3. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  4. hdoj 1002 A + B Problem II 高精度 java

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

  5. hdu1002 A + B Problem II[大数加法]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1002 题干 代码和解释 由题意这是一个涉及到大数的加法问题.去看了一眼大数加法的方法感觉头很大,然后突然发现Java可以流氓解决大数问题,毅 ...

  6. A + B Problem II(大数加法)

    一直格式错误,不想改了,没A #include <iostream> #include <stdio.h> #include <string.h> #include ...

  7. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  8. hdu1002 A + B Problem II(大数题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...

  9. Problem : 1002 ( A + B Problem II )

    经验总结:一定要注意输出的格式,字符的空格,空行,一定要观察清楚.如本题的最后一个输出结果后面没有空行.最后代码实现的时候需要判断一下,代码如下 !=n) cout<<endl; Prob ...

随机推荐

  1. CSS 响应式设计

    响应式设计是指在不同分辨率的设备中,网页布局可以自适应的调整.这种弹性化的布局使网站在不同设备中的布局都比较合理,可以为不同终端的用户提供更加舒适的界面和更好的用户体验,其根本理念是使原本 PC 上的 ...

  2. express开发实例

    express获取参数有三种方法:官网介绍如下 Checks route params (req.params), ex: /user/:id Checks query string params ( ...

  3. Apache配置允许文件索引

    这两天在看bootstrap的文档,所以在本地搭建了一个web server. 这里记下Apache的一个小配置: LISTEN *:8000 <VirtualHost *:8000> A ...

  4. ubuntu16.04添加开机启动任务

    比如要把run-nexus.sh这个脚本制作成开机启动项. 系统工具->首选项->启动应用程序.添加该文件,即可.

  5. UIWebView1-b

    随着H5的强大,hybrid app已经成为当前互联网的大方向,单纯的native app和web app在某些方面显得就很劣势.关于H5的发展史,这里有一篇文章推荐给大家,今天我们来学习最基础的基于 ...

  6. C++的数据类型

    C++的数据类型 计算机处理的对象是数据,而数据是以某种特定的形式存在的(例如整数.浮点数.字符等形式). 不同的数据之间往往还存在某些联系(例如由若干个整数组成一个整数数组).数据结构指的是数据的组 ...

  7. requirejs学习博客址分享

    1. http://blog.jobbole.com/30046/ 2. http://www.requirejs.cn/ 3. http://www.ruanyifeng.com/blog/2012 ...

  8. hdu 4749

    题目很简单,不过题意很难看懂. 就是给一个标准的大小关系的队列,从原队列中找出最多的匹配子队列,感觉就像一个KMP算法+贪心: 不过这个题可能数据有点水把,竟然只要判断相邻的关系就可以A掉: 代码: ...

  9. Cxf + Spring3.0 入门开发WebService

    转自原文地址:http://sunny.blog.51cto.com/182601/625540/ 由于公司业务需求, 需要使用WebService技术对外提供服务,以前没有做过类似的项目,在网上搜寻 ...

  10. 更好的 SQL 模式的 10 条规则

    更好的 SQL 模式的 10 条规则 2015-06-17 11:57:392353浏览1评论 在创建新表和数据仓库时,要做很多决定.一些在当时似乎无关紧要的地方,却让你和用户在数据库的生命期内感到痛 ...