| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为何 Output Limit Exceeded?#include <stdio.h> #include <stdlib.h> #include <string.h> int a1[20]; int a2[20]; char str1[20],str2[20]; void swap(char str[]) { int n,i,j,temp; n=strlen(str); for(i=0,j=n-1;i<j;i++,j--) {temp=str[i]; str[i]=str[j]; str[j]=temp;} } int main() { int t,k1,k2,i,j,max,start,end; scanf("%d",&t); while(t--) { memset(a1,0,sizeof(a1)); memset(a2,0,sizeof(a2)); scanf("%s%s",str1,str2); swap(str1);swap(str2); k1=strlen(str1);k2=strlen(str2); j=0; //printf("%s\n",str1); for(i=k1-1;i>=0;i--) a1[j++]=str1[i]-'0'; // for(j=0;j<k1;j++) //printf("%d",a1[j]); //printf("\n"); j=0; for(i=k2-1;i>=0;i--) a2[j++]=str2[i]-'0'; if(k1>k2) max=k1; else max=k2; for(i=0;i<max;i++) a1[i]=a1[i]+a2[i]; for(i=0;i<max+3;i++) if(a1[i]>9) { a1[i+1]++; a1[i]=a1[i]%10; } i=20; while(a1[i]==0&&i>0) i--; end=i; i=0; while(a1[i]==0&&i<20) i++; start=i; for(i=start;i<=end;i++) printf("%d",a1[i]); printf("\n"); } return 0; //system("pause"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator