Integer Inquiry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8704 Accepted Submission(s): 2211
``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.)
The final input line will contain a single zero on a line by itself.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
1 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
370370367037037036703703703670
//大数相加,化为字符串处理
#include<iostream>
#include<string.h>
using namespace std;
#define MAX 110
int main()
{
int n,len,i,flag,tlen;
char s[MAX];
int sum[MAX];
while(cin>>n)
{
while(n--)
{
memset(sum,0,sizeof(sum));
len=0;
while(cin>>s&&strcmp(s,"0"))
{
tlen=strlen(s);
if(tlen>len)
len=tlen;
for(i=tlen-1;i>=0;i--)
{
sum[tlen-1-i]+=s[i]-'0';
if(sum[tlen-1-i]>9)
{
sum[tlen-1-i]%=10;
sum[tlen-i]+=1;
}
}
}
tlen=0;
for(i=len+6;i>=0;i--)
{
if(sum[i]&&tlen==0)
tlen=1;
if(tlen||i==0)
cout<<sum[i];
}
cout<<endl;
if(n>0)
cout<<endl;
}
}
return 0;
}