QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688001 | #7698. ISBN Conversion | dbaumg | WA | 0ms | 3608kb | C++20 | 2.2kb | 2024-10-29 22:31:57 | 2024-10-29 22:31:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while (t--) {
string s;
cin >> s;
ll n = s.size();
if (s[0] == '-' || s.back() == '-') {
cout << "invalid" << "\n";
continue;
}
ll k = 0;
for (char c : s)
if (c == '-')
k += 1;
if (k > 3) {
cout << "invalid" << "\n";
continue;
}
if (k == 3 && s[n - 2] != '-') {
cout << "invalid" << "\n";
continue;
}
ll m = 0;
ll p = 10;
for (int i = 0; i < n; i++) {
if (s[i] == '-')
continue;
ll cur = s[i] - '0';
if (s[i] == 'X')
cur = 10;
m += cur * p;
m %= 11;
p -= 1;
}
if (m != 0) {
cout << "invalid" << "\n";
continue;
}
string ans = "978-";
ans += s;
ans.pop_back();
bool b = true;
for (int i = 0; i < n - 1; i++) {
if (s[i] == '-' && s[i + 1] == '-') {
cout << "invalid" << "\n";
goto next;
}
}
m = 0;
for (int i = 0; i < ans.size(); i++) {
if (ans[i] == '-')
continue;
ll cur = ans[i] - '0';
if (ans[i] == 'X')
cur = 10;
if (b)
m += cur;
else
m += 3 * cur;
m %= 10;
b = !b;
}
if (b) {
for (int i = 0; i < 10; i++) {
if ((m + i) % 10 == 0) {
ans += '0' + i;
break;
}
}
} else {
for (int i = 0; i < 10; i++) {
if ((m + 3 * i) % 10 == 0) {
ans += '0' + i;
break;
}
}
}
cout << ans << "\n";
next: continue;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
4 3-540-4258-02 039428013X 3-540-42580-2 0-14-028333-3
output:
invalid 978-0394280134 978-3-540-42580-9 invalid
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
25 ---------- ----------- ------------ ------------- XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX ---------X ----------X -----------X 01234567890 012345678901 0123456789012 -0123456789- 0123456789- -0123456789 01--23456789 012345678--9 0123456789-- --0123456789 98765432-1 987-654-321 87-645-32-...
output:
invalid invalid invalid invalid 978-XXXXXXXXX2 978-XXXXXXXXXX4 invalid invalid invalid invalid invalid 978-01234567899 invalid invalid invalid invalid invalid invalid invalid invalid invalid 978-98765432-0 978-987-654-320 978-87-645-32-5 invalid
result:
wrong answer 5th lines differ - expected: 'invalid', found: '978-XXXXXXXXX2'