进位统计
Primary Arithmetic
http://www.nowcoder.com/questionTerminal/c1fb44e931394e6693671f49c899f5de
实际上不用计算加法。
#include <stdio.h> #include <string.h> int main() { char a[10],b[10]; int len1,len2,c,n; while(scanf("%s %s",&a,&b)!=EOF) { if(!strcmp(a,"0")&&!strcmp(b,"0")) break; len1=strlen(a); len2=strlen(b); len1--; len2--; for(c=0,n=0;len1>=0&&len2>=0;len1--,len2--) { if(a[len1]+b[len2]+c-'0'<='9'&&a[len1]+b[len2]+c-'0'>='0') c=0; else{ c=1; n++; } } if(len1>0&&a[len1]+c>'9') n++; else if(len2>0&&b[len2]+c>'9') n++; if(n==0) printf("NO carry operation.\n"); else if(n==1) printf("1 carry operation.\n"); else printf("%d carry operations.\n",n); } return 0; }(•̀ᴗ•́)و