水题。求两个数相加进了多少次位,模拟加法过程即可。
#include<cstdio>
int main()
{
//freopen("in.txt","r",stdin);
int a,b;
while(~scanf("%d%d",&a,&b)){
if(!a && !b) break;
int temp1=0,temp2=0,sum=0,counter=0;
for(;a || b;){
temp1 = a%10; temp2 = b%10;
a/=10 ; b/=10;
sum += temp1 + temp2;
if(sum>=10) counter++;
sum /= 10;
}
if(counter==0) printf("No carry operation.\n");
else if(counter==1) printf("1 carry operation.\n");
else printf("%d carry operations.\n",counter);
}
return 0;
}