QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305948 | #6407. Classical A+B Problem | ckiseki | WA | 1ms | 3804kb | C++20 | 1.8kb | 2024-01-16 06:26:09 | 2024-01-16 06:26:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
string sub(string a, string b) {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
while (a.size() < b.size()) a += "0";
while (b.size() < a.size()) b += "0";
string r = "";
int d = 0;
for (size_t i = 0; i < a.size(); ++i) {
int v1 = a[i] - '0';
int v2 = b[i] - '0';
if (v1 - d - v2 < 0) {
r += char(v1 - d - v2 + 10 + '0');
d = 1;
} else {
r += char(v1 - d - v2 + '0');
d = 0;
}
}
while (r.back() == '0') r.pop_back();
reverse(r.begin(), r.end());
return r;
}
bool geq(string_view a, string_view b) {
if (a.size() != b.size()) return a.size() > b.size();
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] != b[i])
return a[i] > b[i];
}
return true;
}
bool rep(string_view s) {
for (size_t i = 1; i < s.size(); ++i)
if (s[i] != s[i - 1]) return false;
return true;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t; cin >> t;
while (t--) {
string x; cin >> x;
for (int i = 1; i < 10; ++i) {
{
string a(x.size(), char(i + '0'));
if (geq(x, a)) {
auto b = sub(x, a);
if (rep(b)) {
cout << a << ' ' << b << '\n';
break;
}
}
}
{
string a(x.size() - 1, char(i + '0'));
auto b = sub(x, a);
if (rep(b)) {
cout << a << ' ' << b << '\n';
break;
}
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
6 2 786 1332 89110 2333333 10000000000000000000000000001
output:
1 1 777 9 333 999 88888 222 111111 2222222 9999999999999999999999999999 2
result:
ok ok (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3580kb
input:
100 854 77777777781111111111111111110 44444450 11111111111111333 2310 5 333333333333333333333343332 888999 10 11113333 335 77779 88888888888888888888889111111111111111111110 55555555555555777777 72222222222222222222221 666 5777 1111555555 444444444544444444443 88888888888891111111111110 673332 97 77...
output:
777 77 77777777777777777777777777777 3333333333333333333 44444444 6 11111111111111111 222 2222 88 1 4 333333333333333333333333333 9999 888888 111 1 9 11111111 2222 333 2 77777 2 88888888888888888888888888888888888888888888 222222222222222222222 55555555555555555555 222222 5555555555555555555555 6666...
result:
wrong answer Token parameter [name=y] equals to "88888888888", doesn't correspond to pattern "[1-9]{1,2}" (test case 77)