Description
输入多组数据,统计每组数相加得到进位的次数,(整数不超过9位),直到输入0 0结束
Simple Input
123 234
234 987
234 481
0 0
Simple Output
0
3
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include
int main(){
int a,b;
while((scanf("%d%d",&a,&b)) == 2 && a!=0 || b!=0){
int c = 0,ans = 0;
for(;;){
ans += (a % 10 + b % 10 + c)/10?1:0;
c = (a % 10 + b % 10 + c)/10;
a /= 10;
b /= 10;
if(a==0 || b==0){
ans += (a%10 + b%10 + c)/10?1:0;
break;
}
}
printf("%d\n",ans);
}
return 0;
}
two:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include
int main(){
int a,b;
while((scanf("%d%d",&a,&b)) == 2){
if(!a && !b){
return 0;
}
int c = 0,ans = 0;
for(int i = 9;i >= 0;i--){
c = (a % 10 + b % 10 + c)>9?1:0;
ans += c;
a /= 10;
b /= 10;
}
printf("%d\n",ans);
}
return 0;
}
阅读(1908) | 评论(0) | 转发(0) |