今天來解YKL11(UVA10035):Primary Arithmetic
mod取餘數
計算有幾個進位
#include <iostream>
#include <string>
using namespace std;
int main(){
int a,b;
while(cin >> a >> b){
int count = 0,carry = 0;
if(a==0 && b ==0) break;
while(a > 0 || b > 0){
int dig1 = a % 10;
int dig2 = b % 10;
int sum = dig1 + dig2 + carry;
if(sum >= 10){
carry += 1;
count++;
}else{
carry = 0;
}
a /= 10;
b /= 10;
}
if(count == 0) cout << "No carry operation." << endl;
else if(count == 1) cout << "1 carry operation." << endl;
else cout << count << " carry operations." << endl;
}
return 0;
}