QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#855763 | #885. Keep Calm And Carry Off | FUCKUCUP | WA | 0ms | 15576kb | C++20 | 1.4kb | 2025-01-13 10:31:30 | 2025-01-13 10:31:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, a[maxn], b[maxn], tar[maxn];
string s, t;
inline string calc(const string &s1, const string &s2) {
memset(a, 0, sizeof a), memset(b, 0, sizeof b);
for(int i = 0; i < s1.length(); ++i) a[s1.length() - i] = s1[i] - '0';
for(int i = 0; i < s2.length(); ++i) b[s2.length() - i] = s2[i] - '0';
memcpy(tar, a, sizeof a);
int now = 0;
for(int i = 1; i <= n; ++i) if(tar[i] + b[i] > 9) {
now = i, ++tar[i + 1];
if(i == n) ++n;
}
for(int i = 1; i <= now; ++i) tar[i] = 0;
// for(int i = n; i; --i) cout << tar[i]; cout << '\n';
// for(int i = n; i; --i) cout << a[i]; cout << '\n';
for(int i = 1; i <= n; ++i) {
if(tar[i] >= a[i]) tar[i] -= a[i];
else --tar[i + 1], tar[i] = tar[i] + 10 - a[i];
}
// for(int i = n; i; --i) cout << tar[i]; cout << '\n';
string ans;
bool flag = false;
for(int i = n; i; --i) {
if(tar[i]) flag = true;
if(flag) ans += tar[i] + '0';
}
return ans;
}
inline void solve() {
cin >> s >> t, n = max(s.length(), t.length());
string ans1 = calc(s, t), ans2 = calc(t, s);
if(ans1.length() < ans2.length()) cout << ans1 << '\n';
else if(ans1.length() > ans2.length()) cout << ans2 << '\n';
else cout << min(ans1, ans2) << '\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 15276kb
input:
10 99
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 15576kb
input:
90 10
output:
10
result:
ok answer is '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 15576kb
input:
23425 487915
output:
12085
result:
ok answer is '12085'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 15220kb
input:
1 1
output:
result:
wrong output format Unexpected end of file - token expected