poj 1503

来源:互联网 发布:女权癌 知乎 编辑:程序博客网 时间:2024/06/01 17:09
Integer Inquiry
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 34666 Accepted: 13499

Description

One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers. 
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.) 

Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative). 

The final input line will contain a single zero on a line by itself. 

Output

Your program should output the sum of the VeryLongIntegers given in the input.

Sample Input

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900

Sample Output

370370367037037036703703703670
一道大数相加的变形题,比较简单
#include<iostream>#include<string>#include<string.h>using namespace std;#include<algorithm> #include<math.h>int a[110];int main(){string s;int index=0;memset(a,0,sizeof(a));while(cin>>s,s!="0"){for(int i=s.size()-1;i>=0;i--){a[index]+=s[i]-'0';index++;}index=0;}int c=0;for(int i=0;i<110;i++){a[i]+=c;c=a[i]/10;a[i]%=10;}int flag=0;for(int i=109;i>=0;i--){if(a[i]&&!flag){cout<<a[i];flag=1;}else if(flag)cout<<a[i];}cout<<endl;return 0;}


原创粉丝点击