A + B Problem II

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

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<stdlib.h>
#include<string.h>
int main()
{
int m,j,n,i,l1,l2,t,k=1;
char s1[1100];
char s2[1100];
int s3[1100];
int s4[1100];
scanf("%d",&n);
while(n--)
{
scanf("%s %s",s1,s2);
memset(s3,0,sizeof(s3)); //给数组清0
memset(s4,0,sizeof(s4));
l1=strlen(s1);
l2=strlen(s2);
t=0;
for(j=l1-1,i=0;j>=0;j--,i++)
s3[i]=s1[j]-'0'; //将字符串转换为数字
for(j=l2-1,i=0;j>=0;i++,j--)
s4[i]=s2[j]-'0';
for(i=0;i<1100;i++)
{
s3[i]+=s4[i];
if(s3[i]>=10) //对各位求和
{
s3[i]-=10;
s3[i+1]++;
}
}
printf("Case %d:\n",k++);
printf("%s + %s = ",s1,s2);
for(i=1099;i>=0;i--)
if(s3[i]!=0)
break;
for(;i>=0;i--)
printf("%d",s3[i]);
printf("\n");
if(n>0)
printf("\n");
}
return 0;
}

  

 
 

hdoj 1002 A + B Problem II的更多相关文章

  1. hdoj 1002 A + B Problem II【大数加法】

    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 高精度 java

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

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

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

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

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

  5. 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) ...

  6. hduoj 1002 A + B Problem II

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目描述如下: A + B Problem II Time Limit: 2000/1000 M ...

  7. HDU 1002 A + B Problem II

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

  8. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  9. HPU 1002 A + B Problem II【大数】

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

随机推荐

  1. sql快捷键

    请柬:https://msdn.microsoft.com/zh-cn/library/ms174205.aspx

  2. android应用崩溃的调试方法(c++ lib so文件库崩溃)

    android调试工具addr2line使用: 1.将ndk中的arm-linux-androideabi-addr2line可执行文件的路径加入配置文件~/.bashrc中,例如: export P ...

  3. 实例讲解Nginx下的rewrite规则

    一.正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配二.文件及目录匹配,其中:* -f和!-f用来判断是否存在文件* ...

  4. /etc/bashrc,用户目录下.bashrc有什么区别?

    /etc/bashrc,用户目录下.bashrc有什么区别? 一个是针对整个系统所有用户的,一个是针对特定用户的./etc/bashrc修改了以后要重启系统才生效,而用户目录下.bashrc修改了以后 ...

  5. nginx负载均衡 - session失效

    最近迷上了Nginx,真实麻雀虽小,五脏俱全..功能实在强大.. nginx不单可以作为强大的web服务器,也可以作为一个反向代理服务器,而且nginx还可以按照调度规则实现动态.静态页面的分离,可以 ...

  6. 驱动之路-platform简例按键驱动☆☆☆

    一 .重要知识点: ▉1.platform设备模型 从Linux 2.6起引入了一套新的驱动管理和注册机制,platform_device和platform_driver,Linux中大部分的设备驱动 ...

  7. Oracle > count(*) / count(0) / count(1) | order by 1, 2

    select count(*), select count(0), select count(1) from table 在统计表的行数时候,经常用到 select count(*) 然而对于行数很多 ...

  8. 1210. Kind Spirits(spfa)

    1210 简单模版题 敲个spfa还得瞟下模版.. #include <iostream> #include<cstdio> #include<cstring> # ...

  9. poj3468(线段树 边覆盖)

    #include<cstdio> int lb,rb,data; long long sum[5000000],extra[5000000]; void add(int l,int r,i ...

  10. bzoj1471

    转化补集的思想,首先求出任意两点之间路径数目 然后求两条路径第一次相交在点k(按照拓扑排序的顺序)的数目,显然这里要用到容斥 然后pascal有坑爹的范围检测,所以运算中有些不会影响到答案但会爆int ...