Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
1s | 8192K | 1044 | 363 | Standard |
``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.
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
370370367037037036703703703670
This problem is used for contest: 190
#include<stdio.h> #include<iostream> #include<string.h> using namespace std; char num[210]; void convert(char *p,int len) { char temp[110]; for(int i=0,j=len-1;i<len&&j>=0;i++,j--) { temp[i]=p[j]; } temp[len]='\0'; strcpy(p,temp); } int main() { // freopen("in.txt","r",stdin); bool temp=true;int len;int sum[110]={0}; while(scanf("%s",num)==1) { if(strcmp(num,"0")==0)break; if(temp) { temp=false; len=strlen(num)-1; convert(num,len+1); for(int i=0;i<=len;i++) { sum[i]=num[i]-'0'; } } else { int l=strlen(num); convert(num,l); if(len<l-1) { for(int i=0;i<=len;i++) { sum[i]=sum[i]+num[i]-'0'; } for(int i=len+1;i<l;i++) { sum[i]=num[i]-'0'; } len=l-1; } else { for(int i=0;i<l;i++) { sum[i]+=num[i]-'0'; } for(int i=0;i<len;i++) { if(sum[i]>9) { sum[i+1]+=sum[i]/10; sum[i]=sum[i]%10; } } } if(sum[len]>9) { sum[len+1]=sum[len]/10; sum[len]=sum[len]%10; len++; } } } for(int i=len;i>=0;i--) { printf("%d",sum[i]); } printf("\n"); return 0; }这个一个大数加法问题。。。