HDU 1047 Integer Inquiry

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1047

多个数的大数相加问题

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 int a[100000];
 4 char b[100000];
 5 int main()
 6 {
 7     int n,i,j,t,max;
 8     scanf("%d",&n);
 9     getchar();
10     while(n--)
11     {
12         memset(a,0,sizeof(a));
13         while(~scanf("%s",b))
14         {
15             max=1001;
16         if(strcmp(b,"0")==0)
17         {
18             break;
19 
20         }
21         t=strlen(b);
22         j=0;
23         for(i=t-1;i>=0;i--)
24         {
25             a[j]+=b[i]-'0';
26             j++;
27         }
28         for(i=0;i<max;i++)
29         {
30             if(a[i]>=10)
31              {
32                 a[i+1]+=(a[i]/10);
33                 a[i]=a[i]%10;
34              }
35         }
36         }
37             while(!a[max])
38             max--;
39             if(max >= 0)
40             for(i=max;i>=0;i--)
41             {
42             printf("%d",a[i]);
43              }
44              else
45              printf("0");
46         printf("\n");
47         if(n!=0)
48         printf("\n");
49     }
50     return 0;
51 }
原文地址:https://www.cnblogs.com/timeship/p/2622052.html