题解 | #Primary Arithmetic#
Primary Arithmetic
https://www.nowcoder.com/practice/c1fb44e931394e6693671f49c899f5de?tpId=40&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan&difficulty=&judgeStatus=&tags=&title=70&sourceUrl=&gioEnter=menu
#include <stdio.h>
#include <string.h>
//非常简单的代码,应该一目了然,就不解释了
int main() {
int a,b;
while (scanf("%d %d", &a, &b) != EOF) {
if (a==0&&b==0){
break;
}
int count=0;
int jinwei=0; //这是低位的进位
while (a!=0 || b!=0) { //算到两数都变为0,就算两数长短不一也不影响,大不了短的那个后面一直是0
int n1=a%10;
int n2=b%10;
if (n1+n2+jinwei>=10){
count++;
jinwei=1;
}else {
jinwei=0;
}
a/=10;
b/=10;
}
if (count==0){
printf("NO carry operation.\n");
}else if (count==1){
printf("1 carry operation.\n");
}else {
printf("%d carry operations.\n", count);
}
}
return 0;
}
#c#
查看16道真题和解析