QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646742 | #7698. ISBN Conversion | zeyu# | WA | 0ms | 3636kb | C++23 | 2.7kb | 2024-10-17 06:23:33 | 2024-10-17 06:23:33 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif
const ll mod = 1e9 + 7;
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}
void solve(){
string s; cin >> s;
bool bad = false;
int cnt = 0, n = s.size(), sum = 0;
for (int i = 0; i < n - 1; i ++) if (s[i] == '-' && s[i + 1] == '-') bad = true;
if (s[0] == '-' || s[n - 1] == '-') bad = true;
for (int i = 0; i < n; i ++) if (s[i] == '-') cnt ++;
if (cnt > 3) bad = true;
if (cnt == 3 && s[n - 2] != '-') bad = true;
int tt = 10;
for (int i = 0; i < n - 1; i ++){
if (s[i] != '-'){
sum += tt * (s[i] - '0'); tt --;
}
}
sum %= 11; sum = 11 - sum; if (sum == 11) sum = 0;
if ((sum == 10 && s[n - 1] != 'X') || (sum != 10 && s[n - 1] != (char)(sum + '0'))) bad = true;
if (bad) cout << "invalid\n";
else{
string ns = "978-" + s;
int cur = 0, lst = 0; ns.pop_back(); sum = 0;
for (int i = 0; i < ns.size(); i ++){
if (ns[i] != '-'){
if (cur % 2 == 0) sum += ns[i] - '0';
else sum += (ns[i] - '0') * 3;
cur ++;
}
}
sum %= 10; if (sum != 0) lst = 10 - sum;
ns.push_back((char)(lst + '0')); cout << ns << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tc; cin >> tc;
while(tc --){solve();}
}
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: 3636kb
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 978-01234567897 invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid
result:
wrong answer 12th lines differ - expected: 'invalid', found: '978-01234567897'