社区讨论
50求调QAQ
P12381 [蓝桥杯 2023 省 Python B] 保险箱参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjsrfi0
- 此快照首次捕获于
- 2025/11/04 07:54 4 个月前
- 此快照最后确认于
- 2025/11/04 07:54 4 个月前
CPP
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n;
string x, y;
cin >> n >> x >> y;
int res = 0;
int carry = 0;
for (int i = n - 1; i >= 0; --i) {
int a = x[i] - '0' + carry;
int b = y[i] - '0';
carry = 0;
if (a == b) {
continue;
}
int direct = abs(b - a);
int wrap = 10 - direct;
if (direct < wrap) {
res += direct;
} else {
res += wrap;
if (b > a) {
carry = -1;
}
else {
carry = 1;
}
}
}
cout << res << endl;
return 0;
}
不知道哪里错了QAQ
回复
共 0 条回复,欢迎继续交流。
正在加载回复...