QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697137 | #7698. ISBN Conversion | BackToSquare1 | WA | 0ms | 3560kb | C++20 | 2.4kb | 2024-11-01 11:07:11 | 2024-11-01 11:07:11 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
#define NN 2000005
#define MM 5005
#define MOD 1000000007
void solve() {
string s;
cin >> s;
ll hyphenCount = 0;
vector<ll> digits;
ll n = s.length();
if(n < 3) {
cout << "invalid\n";
return;
}
bool ok = 1;
for(ll i=0;i<n-1;i++) {
if(s[i] >= '0' && s[i] <= '9') {
digits.push_back((ll)(s[i] - '0'));
}
else if(s[i] == '-') hyphenCount++;
else {
ok = 0;
// cout << "HI1\n";
}
}
if(s[n-1] >= '0' && s[n-1] <= '9') digits.push_back((ll)(s[n-1] - '0'));
else if(s[n-1] == 'X') digits.push_back(10);
else {
ok = 0;
// cout << "HI2\n";
}
if(hyphenCount > 3) ok = 0;
for(ll i=1;i<n;i++) {
if(s[i] == '-' && s[i-1] == '-') ok = 0;
}
if(digits.size() != 10) ok = 0;
if(hyphenCount == 3 && s[n-2] != '-') ok = 0;
// cout << "WTF1\n";
if(!ok) {
cout << "invalid\n";
return;
}
// cout << "WTF2\n";
ll sum = 0;
for(ll i=0;i<10;i++) {
sum += (10-i)*digits[i];
}
if(sum%11 != 0) {
cout << "invalid\n";
return;
}
// cout << "WTF3\n";
string ans = "978-" + s;
ll k = ans.size();
vector<ll> newDigits = {9,7,8};
for(ll i=0;i<9;i++) {
newDigits.push_back(digits[i]);
}
ll newSum = 0;
for(ll i=0;i<12;i++) {
if(i%2 == 0) newSum += newDigits[i];
else newSum += 3*newDigits[i];
}
ll num = (10 - (newSum%10))%10;
ans[k-1] = (char)(num + '0');
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
G(t);
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 3560kb
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 invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid 978--0123456786 invalid invalid invalid invalid invalid invalid invalid invalid
result:
wrong answer 17th lines differ - expected: 'invalid', found: '978--0123456786'