题目描述:
很多小学生在学习加法时,发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记)。
输入描述:
输入两个正整数m,n.(m,n,都是三位数)
输出描述:
输出m,n,相加时需要进位多少次。
样例输入:
复制
123 456 555 555 123 594 0 0
样例输出:
0 3 1
#include <iostream>
using namespace std;
int main()
{
int x,y;
while((cin>>x>>y&&(x+y)!=0)){
int flag=0,n=0;
if((x%10)+(y%10)>=10){
flag=1;
n++;
}
if((x/10%10)+(y/10%10)+flag>=10){
n++;
}
else
flag=0;
if((x/100)+(y/100)+flag>=10){
flag=1;
n++;
}
cout<<n<<endl;
}
}