萌新求教,无法退出程序是为何,我这个输出格式对吗?

P1957 口算练习题

```cpp #include <iostream> #include <cstdio> using namespace std; int n; string c; char kind; int num1, num2; int ans; int forbid; void counting() { ans = 0; if(num1 - num2 < 0 && kind == 'b') ans++; if(num1 == 0) ans++; if(num2 == 0) ans++; if(forbid == 0) ans++; while(num1) { ans++; num1 /= 10; } while(num2) { ans++; num2 /= 10; } while(forbid) { ans++; forbid /= 10; } ans += 2; } void thoue() { if(kind == 'a') { cout << num1 << "+" << num2 << "=" << num1+num2 << endl; forbid = num1+num2; } else if(kind == 'b') { cout << num1 << "-" << num2 << "=" << num1-num2 << endl; forbid = num1-num2; } else { cout << num1 << "*" << num2 << "=" << num1*num2 << endl; forbid = num1*num2; } } int main() { cin >> n; while(n--) { cin >> c; num1 = 0; num2 = 0; ans = 0; if(c[0] >= 'a' && c[0] <= 'c') { kind = c[0]; cin >> num1 >> num2; thoue(); counting(); cout << ans << endl; } else { for(int k = 0; k < c.length(); k++) { num1 += c[k] - '0'; if(k != (c.length() - 1)) num1 = 10 * num1; } cin >> num2; thoue(); counting(); cout << ans << endl; } } return 0; } ```
by 芝麻馅儿汤圆 @ 2021-08-24 00:05:40


|