标签:style blog io ar color sp for div log
1 #include <stdio.h> 2 #include <string.h> 3 char a[1000],b[1000];int c[1005]; 4 int main () 5 { 6 int t,m,n; 7 scanf( "%d" , &t); 8 for ( int i = 1; i <= t; ++i) 9 { 10 scanf( "%s%s" ,a ,b ); 11 printf( "Case %d:\n", i); 12 printf( "%s + %s = " ,a ,b ); 13 n=strlen(a)-1; 14 m=strlen(b)-1; 15 int p = 0, k; 16 for ( k=0 ; n >= 0 || m>=0 ;k++ ,n-- ,m--) 17 { 18 if( n >= 0 && m>= 0 ) 19 c[k]=a[n] - ‘0‘ + b[m] - ‘0‘+p; 20 if( n >= 0 && m < 0 ) 21 c[k]=a[n]-‘0‘+p ; 22 if ( n < 0 && m >= 0 ) 23 c[k]=b[m]-‘0‘+p ; 24 p=0; 25 if(c[k]>9) 26 { 27 c[k]=c[k]-10; 28 p=1; 29 } 30 } 31 if(p==1) 32 printf("%d",p); 33 while(k--) 34 printf( "%d" , c[k]); 35 if( i<t ) 36 {printf("\n\n");} 37 else 38 {printf("\n");} 39 } 40 return 0; 41 }
标签:style blog io ar color sp for div log
原文地址:http://www.cnblogs.com/lonelysky/p/4117502.html