2
100
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
0
11
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
0
我该啦,但是还是错啦。。。上面我测试数据:
#include<iostream>
using namespace std;
#define T 110
char a[110][110];
int d[110],p[T];
int k,i,j,R;
int main()
{
freopen("D:\\in.txt","r",stdin);
scanf("%d",&R);
while(R--)
{
k=0;
getchar();
while(1)
{
scanf("%s",a[++k]);
if(strcmp(a[k],"0")==0)
break;
}
int max_len=0;
for(i=1;i<k;i++)
{
d[i]=strlen(a[i]);
if(d[i]>max_len)
max_len=d[i];
}
for(i=1;i<k;i++)
{
for(j=0;j<d[i];j++)
a[i][j]-='0';
}
memset(p,0,sizeof(p));
for(i=max_len-1;i>=0;i--)
{
for(j=1;j<k;j++)
{
if(d[j]>0)
{
p[i]+=a[j][--d[j]];
}
}
}
for(i=max_len-1;i>0;i--)
{
p[i-1]+=p[i]/10;
p[i]=p[i]%10;
}
if(p[0]>=10)
{
printf("%d",p[0]/10);
p[0]=p[0]%10;
}
for(i=0;i<=max_len-1;i++)
{
printf("%d",p[i]);
}
printf("\n");
if(R!=0) printf("\n");
}
return 0;
}