POJ 1503

 1 #include <iostream>
 2 #include <string>
 3 #define MAXN 100000
 4 using namespace std;
 5 
 6 //string _s[MAXN];
 7 int ans[MAXN];
 8 
 9 int main()
10 {
11     //freopen("acm.acm","r",stdin);
12     string s;
13     int i;
14     int index;
15     memset(ans,0,sizeof(ans));
16     index = 0;
17     while(cin>>s,s != "0")
18     {
19         for(i = s.length()-1; i >= 0; -- i)
20         {
21             ans[index ++] += s[i]-'0';
22         }
23         index = 0;
24     }
25     int c;
26     int tem;
27     c = 0;
28     for(i = 0; i < MAXN; ++ i)
29     {
30         ans[i] += c;
31         c = ans[i]/10;
32         ans[i] %= 10;
33     }
34     bool boo = false;
35     for(i = MAXN-1; i >= 0; -- i)
36     {
37         if(ans[i] != 0 && !boo)
38         {
39             cout<<ans[i];
40             boo = true;
41         }
42         else if(boo)
43             cout<<ans[i];
44     }
45     cout<<endl;
46 }

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

原文地址:https://www.cnblogs.com/gavinsp/p/4563417.html