题目描述
小学生的加法运算想必各位学弟学妹都知道吧(不知道的话,这道题就可以不用做了)。小学生在学习加法时,发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记)。
输入
输入数据有多组,输入两个正整数m,n.(m,n,都是三位数),输入两个0时,输入结束
输出
每组数据输出一个整数,表示m,n,相加时需要进位多少次。
样例输入
123 456
555 555
123 594
0 0
样例输出
0
3
1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int first,second;
int fir_one,fir_two,fir_three;
int sec_one,sec_two,sec_three;
while(scanf("%d %d",&first,&second)&&(first||second))
{
fir_one=first/100;
sec_one=second/100;
fir_two=first/10%10;
sec_two=second/10%10;
fir_three=first%10;
sec_three=second%10; //分别处理每一位
int next=0;
int times=0;
if(fir_three+sec_three>=10)
{
next=(fir_three+sec_three)/10;
times++;
}
if(fir_two+sec_two+next>=10)
{
next=(fir_two+sec_two+next)/10;
times++;
}
if(fir_one+sec_one+next>=10)
{
times++;
}
printf("%d\n",times);
}
return 0;
}