Integer Inquiry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15694 Accepted Submission(s): 4027
``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
反过来时顺便转成int。。。还有格式问题 还有就是a1每次都要初始化 否则影响接下来结果
#include<cstdio> #include<iostream> #include<cstring> #include<string> using namespace std; char s[1005]; int a1[1005]={0}; int a2[1005]={0}; int main() { int n=0; scanf("%d",&n); getchar(); while(n--) { int k2=1; memset(s,0,sizeof(s)); memset(a1,0,sizeof(a1)); memset(a2,0,sizeof(a2)); while(gets(s)) { int len=strlen(s); int i=0,k1=0; if(s[0]=='0') break; for(i=len-1;i>=0;i--) { a1[k1++]=s[i]-'0'; } int max=k1>k2?k1:k2; int k=0; int j=0; for(j=0;j<max;j++) { a2[j]=a2[j]+a1[j]+k; k=a2[j]/10; a2[j]%=10; } memset(a1,0,sizeof(a1)); if(k) { a2[j]=k; k2=j+1; } else { k2=j; } } for(int i=k2-1;i>=0;i--) { printf("%d",a2[i]); } printf("\n"); if(n!=0) printf("\n"); } return 0; }