QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#855763#885. Keep Calm And Carry OffFUCKUCUPWA 0ms15576kbC++201.4kb2025-01-13 10:31:302025-01-13 10:31:30

Judging History

你现在查看的是最新测评结果

  • [2025-01-13 10:31:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15576kb
  • [2025-01-13 10:31:30]
  • 提交

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