zoj 1292 Integer Inquiry(大数)

好久没做大数了,虽然做着还算顺利,就是有些地方忘记初始化了,调了半天。。。

 

交过去PE了4次。。。我哭。。下次一定要把题目看清楚!!!无语了都。。

 

#include <stdio.h> #include <stdlib.h> #include <string.h> char s1[102],s2[102]; int num2[102]; void init() { memset(num2,0,sizeof(num2)); } int main(void) { int ncases,i,len1,len2,num1[102],k=0,maxlen; scanf("%d",&ncases); while(ncases--) { scanf("%s",s1); len1 = strlen(s1); maxlen = len1; k = 0; memset(num1,0,sizeof(num1)); for(i=len1-1; i>=0; i--) { num1[k++] = s1[i] - '0'; } while(scanf("%s",s2) && strcmp(s2,"0")) { init(); k = 0; len2 = strlen(s2); for(i=len2-1; i>=0; i--) num2[k++] = s2[i] - '0'; for(i=0; i<len2; i++) num1[i] += num2[i]; if(len2>maxlen) maxlen = len2; } for(i=0; i<maxlen; i++) { if( num1[i] >=10 ) { num1[i+1] += num1[i]/10; num1[i] %= 10; } } if( num1[maxlen] != 0 ) maxlen++; for(i=maxlen-1; i>=0; i--) printf("%d",num1[i]); if( ncases ) printf("/n/n"); } system("pause"); return 0; }

你可能感兴趣的:(zoj 1292 Integer Inquiry(大数))