HDU1229
水题~~~
注意:若k比a,b大,默认没有的位数上为0!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 int main(){ 6 int a,b,k; 7 while( scanf("%d%d%d",&a,&b,&k)!=EOF ){ 8 if( a==0&&b==0 ) 9 break; 10 char aa[ 24 ],bb[ 24 ]; 11 memset( aa,0,sizeof( aa )); 12 memset( bb,0,sizeof( bb )); 13 int lena,lenb,tmp; 14 tmp=a;lena=0; 15 while( tmp!=0 ){ 16 aa[ lena++ ]=tmp%10; 17 tmp/=10; 18 } 19 //aa[ lena ]='\0'; 20 tmp=b;lenb=0; 21 while( tmp!=0 ){ 22 bb[ lenb++ ]=tmp%10; 23 tmp/=10; 24 } 25 // bb[ lenb ]='\0'; 26 int flag=-1; 27 for( int i=0;i<k;i++ ){ 28 if( aa[i]!=bb[i] ){ 29 flag=1; 30 break; 31 } 32 } 33 if( flag==1 ) 34 printf("%d\n",a+b); 35 else 36 printf("-1\n"); 37 } 38 return 0; 39 }
keep moving...