复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <stdio.h> #include <string.h> main() { char a[1010],b[1010];int T,k,aa[1010],bb[1010],cc[1010],lena,lenb,lenc,i,x,flag=0; freopen("1.txt","r",stdin); //freopen("2.txt","w",stdout); scanf("%d",&T); for(k=1;k<=T;k++) { memset(a,'',sizeof(a));memset(b,'',sizeof(b)); scanf("%s%s",&a,&b);lena=strlen(a);lenb=strlen(b); memset(aa,0,sizeof(aa));memset(bb,0,sizeof(bb));memset(cc,0,sizeof(cc)); for(i=0;i<lena;i++)aa[lena-i-1]=a[i]-48;//把lena-i-1改成lena-i就会报错 for(i=0;i<lenb;i++)bb[lenb-i-1]=b[i]-48; lenc=0;x=0; while(lenc<lena||lenc<lenb) { cc[lenc]=aa[lenc]+bb[lenc]+x; x=cc[lenc]/10; cc[lenc]%=10; lenc++; } cc[lenc]=x; if(cc[lenc]==0)lenc--; if(flag)printf("nCase %d:n",k); if(!flag){flag=1;printf("Case %d:n",k);} printf("%s + %s = ",a,b); for(i=lenc;i>=0;i--)printf("%d",cc[i]); putchar('n'); } return 0; }
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
复制代码
1
2
32 1 2 112233445566778899 998877665544332211
复制代码
1
2
3
4
5Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
最后
以上就是文艺马里奥最近收集整理的关于大数专题A - A + B Problem II的全部内容,更多相关大数专题A内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复