(CPE)Primary Arithmetic

Description

In elementary school, we all did the addition operation, which is to align two integers to the right and then add them one by one from right to left. If the added result is greater than or equal to 10, a carry occurs. Your task is to determine how many carries occur when two integers are added. This will help primary school teachers analyze the difficulty of addition problems.

在小學時我們都做過加法的運算,就是把2個整數靠右對齊然後,由右至左一位一位相加。如果相加的結果大於等於10就有進位(carry)的情況出現。你的任務就是要判斷2個整數相加時產生了幾次進位的情況。這將幫助小學老師分析加法題目的難度。

Input

Each column of test data has 2 positive integers, and the length is less than 10 digits. There are two 0s in the last column to indicate the end of input.

每一列測試資料有2個正整數,長度均小於10位。最後一列有2個0代表輸入結束。

Output

Each column of test data outputs how many carries are generated when the two numbers are added. Please refer to Sample Output. Note that when there is more than 1 carry, the operation adds s.

每列測試資料輸出該2數相加時產生多少次進位,請參考Sample Output。注意進位超過1次時operation有加s。

Sample Input 1

Sample Input 2

123 456
555 555
123 594
0 0
99 99
999 99
99 999
99 0
0 99
0 0

Sample Output 1

Sample Output 2

No carry operation.
3 carry operations.
1 carry operation.
2 carry operations.
3 carry operations.
3 carry operations.
No carry operation.
No carry operation.
#include<stdio.h>
#include<stdlib.h>

int count_carry_operation(int an, int bn, int cn){
	int counter = 0;
	
//	first array for the answer
	int c=0;
	int c1 = 0;
	int c2 = 0;
	int k=0;
	for(int i = an; i>0; i=i/10){
			c++;
			k++;
		}
	int a[c];
	for(int i = 0; i<c; i++){
		a[i] = an - an/10*10;
		an=an/10;
	}
	for(int i = 0; i<c; i++){
//		printf("%d\\n",a[i]);
	}
	
//	second array for the b
	for(int i = bn; i>0; i=i/10){
			c1++;
		}
	int b[c1];
	for(int i = 0; i<c1; i++){
		b[i] = bn - bn/10*10;
		bn=bn/10;
	}
	for(int i = 0; i<c1; i++){
//		printf("%d\\n",b[i]);
	}

	//	third array for the ca
	for(int i = cn; i>0; i=i/10){
			c2++;
		}
	int ca[c2];
	for(int i = 0; i<c2; i++){
		ca[i] = cn - cn/10*10;
		cn=cn/10;
	}
	for(int i = 0; i<c2; i++){
//		printf("%d\\n",ca[i]);
	}

	
	
	
	for(int i = 0; i<c1;i++){
		if(b[i]+ca[i]>9){
			counter++;
		}
	} 

	return counter;

}

int main(){
//	if the digit of the sum integer is smaller than one or both inital integer,theres a carried operator
	int n=-1;
	int m = -1;
	int t = 0;
	int count = 0;
	int j = 0;
	while(n+m!=0){
		scanf("%d %d",&n, &m);
		if(n+m==0){
			break;
		}
		if(count_carry_operation(n+m,n,m)==0){
			printf("No carry operation.");
		}else{
			printf("%d carry operations.\\n",count_carry_operation(n+m,n,m));
		}
	}
	
	
	
	return 0;
}