题解 | #还是A+B#
还是A+B
https://www.nowcoder.com/practice/8c3c5dae2c4a4266ba04f993a18e286b
#include <iostream>
using namespace std;
bool isSame(string a, string b, int k) {
if (k > a.size())
k = a.size();
if ( k > b.size()) k = b.size();
for (int i = 0; i < k; i++) {
if (a[a.size() - 1 - i] != b[b.size() - 1 - i]) return false;
}
return true;
}
int main() {
string a, b;
int k;
while (cin >> a >> b >> k) { // 注意 while 处理多个 case
// cout << a + b << endl;
if (a == "0" && b == "0") break;
if (isSame(a, b, k)) {
cout << -1 << endl;
} else {
cout << atoi(a.data()) + atoi(b.data()) << endl;
}
}
}
// 64 位输出请用 printf("%lld")
查看11道真题和解析
海康威视公司福利 1125人发布