题解 | #还是A+B#
还是A+B
https://www.nowcoder.com/practice/8c3c5dae2c4a4266ba04f993a18e286b
#include <iostream> using namespace std; int main() { int a, b, k; while (cin >> a >> b >> k && a && b) { int ans = a + b, flag = 1; while (k-- && a && b) { int t1 = a % 10; int t2 = b % 10; if (t1 != t2) { flag = 0; break; } a /= 10; b /= 10; } if (flag) cout << -1 << endl; else cout << ans << endl; } }