zoj 2001

  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 

 题目很罗嗦,猛一看还以为多麻烦呢,因为刚开始的时候题目提到要把所给的那些数都倒过来,但是好在后面又说了,把所给的数倒过来相加后再倒过来输出。这就好比是负负得正,所以这就是一道大整数的水题了。只要注意前导零的处理,和输入都是零时输出零就可以A掉了

http://acm.hdu.edu.cn/showproblem.php?pid=2100  这是HDU 一道类似的题目

 1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 using namespace std;
5 #define N 10001
6 char str[N],sbr[N];
7 int a[N],b[N];
8 int main()
9 {
10 int i,j,len,len1,len2;
11 int t;
12 cin>>t;
13 while(t--)
14 {
15 memset(a,0,sizeof(a));
16 memset(b,0,sizeof(b));
17 cin>>str>>sbr;
18 len1=strlen(str);
19 len2=strlen(sbr);
20 len=len1>len2?len1:len2;
21 for(i=0;i<len1;i++)
22 a[i]=str[i]-'0';
23 for(i=0;i<len2;i++)
24 b[i]=sbr[i]-'0';
25 for(i=0;i<len;i++)
26 {
27 a[i]+=b[i];
28 if(a[i]>9)
29 {
30 a[i]-=10;
31 a[i+1]++;
32 }
33 }
34 i=0;
35 int flag=0;
36 while(!a[i])
37 {
38 i++;
39 if(i==len+1)
40 {
41 cout<<"0\n"; //保证有零的输出
42 flag=1;break;
43 }
44 }
45 if(flag) continue;
46 len=a[len]?len:len-1; // 这里是判断最后一位的进位
47 for(j=i;j<=len;j++)
48 cout<<a[j];
49 cout<<endl;
50 }
51 return 0;
52 }


原文地址:https://www.cnblogs.com/fxh19911107/p/2274576.html