#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long first, second;
int mod, carry;
vector <int> carry1, carry2;
while(cin >> first >> second){
if(first == 0 && second == 0)break;
while(first > 0){
mod = first % 10;
carry1.push_back(mod);
first -= mod;
first /= 10;
}
while(second > 0){
mod = second % 10;
carry2.push_back(mod);
second -= mod;
second /= 10;
}
int l1, l2, mn, mx, ans = 0, in_hand = 0, push;
l1 = carry1.size(), l2 =carry2.size();
mn = min(l1, l2);
mx = max(l1, l2);
push = mx - mn;
for(int i = 0; i < push; i++){
if(l1 > l2)carry2.push_back(0);
if(l1 < l2)carry1.push_back(0);
}
for(int i = 0; i < mx; i++){
carry = carry1[i] + carry2[i] + in_hand;
if(carry >= 10){
ans++;in_hand = 1;
}
else in_hand = 0;
}
if(ans == 0)cout << "No carry operation." << endl;
else if(ans == 1)cout << ans << " carry operation." << endl;
else cout << ans << " carry operations." << endl;
carry1.clear(), carry2.clear();
}
return 0;
}
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long first, second;
int mod, carry;
vector <int> carry1, carry2;
while(cin >> first >> second){
if(first == 0 && second == 0)break;
while(first > 0){
mod = first % 10;
carry1.push_back(mod);
first -= mod;
first /= 10;
}
while(second > 0){
mod = second % 10;
carry2.push_back(mod);
second -= mod;
second /= 10;
}
int l1, l2, mn, mx, ans = 0, in_hand = 0, push;
l1 = carry1.size(), l2 =carry2.size();
mn = min(l1, l2);
mx = max(l1, l2);
push = mx - mn;
for(int i = 0; i < push; i++){
if(l1 > l2)carry2.push_back(0);
if(l1 < l2)carry1.push_back(0);
}
for(int i = 0; i < mx; i++){
carry = carry1[i] + carry2[i] + in_hand;
if(carry >= 10){
ans++;in_hand = 1;
}
else in_hand = 0;
}
if(ans == 0)cout << "No carry operation." << endl;
else if(ans == 1)cout << ans << " carry operation." << endl;
else cout << ans << " carry operations." << endl;
carry1.clear(), carry2.clear();
}
return 0;
}
No comments:
Post a Comment