#include <iostream>
using namespace std;
//c014. 10035 - Primary Arithmetic
int main() {
int a, b, count=0,carry=0;
while (cin >> a >> b) {
if (a == 0 && b == 0) {
return 0;
}
count = 0;
while (a > 0 || b > 0) { //為處理不同位數相加
if (((a % 10) + (b % 10) + carry) >= 10) { //初始carry設為0,從最低位做相加
count++;
carry = 1; //carry會加到下一位
}
else {
carry = 0;
}
a /= 10; //若輸入268,則下個loop的a變成26
b /= 10;
}
if (count == 0) {
cout << "No carry operation.";
}
else if (count == 1) {
cout << "1 carry operation.";
}
else {
cout << count << " carry operations.";
}
cout << "\n";
}
return 0;
}
我丟測資會過,自己也測試過9999+1和2952+48等都正常,
但送出解答後會是WA(line:31),我的答案會是2 carry,系統:No carry
#include
using namespace std;//c014. 10035 - Primary Arithmetic
int main() {
int a, b, count=0,carry=0;
while (cin >> a >> b) {
if (a == 0 && b == 0) {
return 0;
}
count = 0 , carry=0;
while (a > 0 || b > 0) { //為處理不同位數相加
if (((a % 10) + (b % 10) + carry) >= 10) { //初始carry設為0,從最低位做相加
count++;
carry = 1; //carry會加到下一位
}
else {
carry = 0;
}
a /= 10; //若輸入268,則下個loop的a變成26
b /= 10;
}
if (count == 0) {
cout << "No carry operation.";
}
else if (count == 1) {
cout << "1 carry operation.";
}
else {
cout << count << " carry operations.";
}
cout << "\n";
}return 0;
}
我丟測資會過,自己也測試過9999+1和2952+48等都正常,
但送出解答後會是WA(line:31),我的答案會是2 carry,系統:No carry