QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552984 | #7698. ISBN Conversion | SpaceQuark# | AC ✓ | 4ms | 18920kb | C++20 | 5.0kb | 2024-09-08 05:00:09 | 2024-09-08 05:00:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
/* TYPES */
#define tcT template <class T
#define tcTU tcT, class U
#define tcTUW tcTU, class W
using ll = long long;
using db = long double;
using str = string;
/* PAIRS */
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
/* VECTORS */
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vvi = V<V<int>>;
using vb = V<bool>;
using vl = V<ll>;
using vvl = V<V<ll>>;
using vd = V<db>;
using vc = V<char>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
#define sz(x) int(size(x)) // (ll)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define view(x, a) V<decltype(x)::value_type> (bg(x), bg(x)+a+1)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
#define sum(v) accumulate(all(v), 0ll)
/* UNORDERED MAP SET */
#define timeStamp() std::chrono::steady_clock::now()
struct custom_hash {static uint64_t xs(uint64_t x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);} size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = timeStamp().time_since_epoch().count(); return xs(x + FIXED_RANDOM);} size_t operator()(const pl& p) const {static const uint64_t FIXED_RANDOM = timeStamp().time_since_epoch().count(); return xs((uint64_t)p.fi) + ((uint64_t)p.se) * FIXED_RANDOM;}};
tcTU > using UM = unordered_map<T, U, custom_hash>;
tcT > using US = unordered_set<T, custom_hash>;
using umll = UM<ll, ll>;
using umcl = UM<char, ll>;
using umsl = UM<str, ll>;
using usl = US<ll>;
using usc = US<char>;
using uss = US<str>;
#define has(s, x) (s.find(x) != end(s))
/* LOOPS */
#define FOR(i, s, e) for (ll i = (s); i < (e); ++i)
#define CFOR(i, s, e) for (ll i = (s); i <= (e); ++i)
#define ROF(i, e, s) for (ll i = (e)-1; i >= (s); --i)
#define each(a, x) for (auto &a : x)
#define eachkv(k, v, mp) for (auto &[k, v] : mp)
/* CONSTANTS */
const char nl = '\n';
const int MOD = 998244353; // 1e9+7;
const int MX = (int)2e6 + 5;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1}; // for every grid problem!!
const int dr[4]{1, -1, 1, -1}, dc[4]{1, 1, -1, -1}; // for every diagonal problem!!
mt19937 rng((uint32_t)timeStamp().time_since_epoch().count());
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
/* FUNCTIONS */
tcT > UM<T, ll> counter(V<T> &v){ UM<T, ll> mp; each(a, v){ if (mp.count(a)){mp[a]++;} else{mp[a] = 1;} } return mp;}
UM<char, ll> counter(str &v){ UM<char, ll> mp; each(a, v){ if (mp.count(a)){mp[a]++;} else{mp[a] = 1;} } return mp;}
tcTU > V<pair<T, U>> keyvals(UM<T, U> &mp){V<pair<T, U>> vp; eachkv(k,v,mp){vp.eb(k, v);} return vp;}
tcT > V<T> idxter(V<T> v){V<T> idxs(MX, -1);FOR(i,0,sz(v)){idxs[v[i]] = i;}return idxs;}
tcT > void remDup(V<T> &v) {sort(all(v)); v.erase(unique(all(v)), end(v));}
tcTU > void ese(T &t, const U &u) {auto it = t.find(u); t.erase(it);}
// [](const auto& a, const auto& b) {return a.se < b.se;}
/* TESTING */
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL);
#define rd(...) ([](auto&&... args) { (cin >> ... >> args); }(__VA_ARGS__))
#define rdv(v) each(x, v) { rd(x);}
#define wrtl(...) ([](auto&&... args) { (cout << ... << args) << endl; }(__VA_ARGS__))
#define YES wrtl("YES")
#define NO wrtl("NO")
vl dp(MX, 0);
// vvl dp(m, vl(n, 0)); // m x n
bool check(str& s){
ll n = sz(s);
ll tothyp = 0, totdig = 0, mult = 10, tot = 0;
if (n < 10 || n > 13){
return false;
}
ll xpos = s.find('X');
if (xpos != n-1 && xpos != -1){
// dbg(n-1, xpos);
return false;
}
// last character check after
FOR(i,0,n-1){
if (s[i] == '-'){
tothyp++;
if (s[i+1] == '-'){
return false;
}
} else{ // digit
tot += (s[i] - '0') * mult;
mult--;
}
}
if (s[0] == '-' || s[n-1] == '-'){
return false;
}
if (n - tothyp != 10){
return false;
}
if (tothyp > 3 || (tothyp == 3 && s[11] != '-')){
return false;
}
char last = s[n-1];
if (last == 'X'){
tot += 10;
} else{
tot += (last - '0');
}
if (tot % 11 != 0){
return false;
}
return true;
}
ll conv(str& s){
ll n = sz(s);
ll mult = 3, tot = 9+7*3 + 8*1;
FOR(i,0,n-1){
if (s[i] != '-'){
tot += mult * (s[i] - '0');
mult = mult ^ 3 ^ 1;
}
}
tot %= 10;
return (10 - tot) % 10;
}
void solve(){
str s; rd(s);
if (!check(s)){
cout << "invalid" << nl;
} else{
cout << "978-" << s.substr(0, sz(s)-1) << conv(s) << nl;
}
}
int main(){
fastio;
ll t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 18920kb
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: 0
Accepted
time: 0ms
memory: 18704kb
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 invalid invalid invalid invalid invalid invalid invalid invalid invalid
result:
ok 25 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 18536kb
input:
5 71234567X1 71234567X-1 2-2345678-9 8X-7X-123456 7123X8123X
output:
invalid invalid invalid invalid invalid
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 18688kb
input:
10 3-540-42580-X 3-540-42580-3 0393609394 0-19-853453-9 0070131510 0070131512 0070131514 0070131516 0070131518 007013151X
output:
invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 18660kb
input:
11 767-13423100 65955-01-15-1 778592-4222 3283-138-073 8-802896-37-4 514-2481525 356-52708-6-6 4-810-73599-7 3-28438-244-8 1-98-2031209 82-54-55344X
output:
invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid
result:
ok 11 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 18640kb
input:
12 0123456789 0-19-853453-1 0070131511 0-07-0131511 039428013-X 0-39-428013X 0-3942801-3X 0131103628 3-540-42580-2 3540425802 1535956828 1535-9-5682-8
output:
978-0123456786 978-0-19-853453-2 978-0070131514 978-0-07-0131514 978-039428013-4 978-0-39-4280134 978-0-3942801-34 978-0131103627 978-3-540-42580-9 978-3540425809 978-1535956826 978-1535-9-5682-6
result:
ok 12 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 18640kb
input:
10 69289-01810 07-8-2406750 4946302-980 91-45-00652-0 2526831830 8370591930 022-18967-4-0 86340-22-25-0 862-57-6642-0 1691783730
output:
978-69289-01810 978-07-8-2406757 978-4946302-985 978-91-45-00652-8 978-2526831832 978-8370591939 978-022-18967-4-3 978-86340-22-25-4 978-862-57-6642-6 978-1691783731
result:
ok 10 lines
Test #8:
score: 0
Accepted
time: 2ms
memory: 18640kb
input:
10 5-401032021 5240-54-427-1 9-180-978371 931-918-0741 4696037371 4087-1938-6-1 87-000442-6-1 6917-1319-11 1-765295351 5031540591
output:
978-5-401032027 978-5240-54-427-9 978-9-180-978378 978-931-918-0740 978-4696037373 978-4087-1938-6-2 978-87-000442-6-5 978-6917-1319-14 978-1-765295351 978-5031540596
result:
ok 10 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 18832kb
input:
10 3-457991-81-2 39984-91252 423300-4-932 3275898582 9366799-442 0557387302 45-91615812 251-19985-7-2 6055184192 81622230-0-2
output:
978-3-457991-81-7 978-39984-91258 978-423300-4-936 978-3275898589 978-9366799-445 978-0557387304 978-45-91615812 978-251-19985-7-1 978-6055184193 978-81622230-0-0
result:
ok 10 lines
Test #10:
score: 0
Accepted
time: 0ms
memory: 18644kb
input:
10 7876-3592-1-3 79129531-83 9-109-06704-3 82865161-33 2-9-35967283 49919695-73 7576775513 3-843660123 004739-25-33 509-758-044-3
output:
978-7876-3592-1-0 978-79129531-81 978-9-109-06704-6 978-82865161-32 978-2-9-35967283 978-49919695-77 978-7576775518 978-3-843660129 978-004739-25-35 978-509-758-044-4
result:
ok 10 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 18748kb
input:
10 27-6658-1154 457995-2774 0-878349-634 8230808074 663-1-368014 9439-7026-6-4 365-0-59504-4 0158386574 902-1-41617-4 8573813814
output:
978-27-6658-1153 978-457995-2779 978-0-878349-630 978-8230808078 978-663-1-368016 978-9439-7026-6-2 978-365-0-59504-1 978-0158386577 978-902-1-41617-5 978-8573813814
result:
ok 10 lines
Test #12:
score: 0
Accepted
time: 0ms
memory: 18792kb
input:
10 800-978040-5 4855-4-6463-5 61561839-65 9830-08479-5 2859817395 00324136-45 0985-8-6474-5 6624604875 0-83181632-5 32786193-15
output:
978-800-978040-6 978-4855-4-6463-7 978-61561839-65 978-9830-08479-4 978-2859817398 978-00324136-41 978-0985-8-6474-3 978-6624604879 978-0-83181632-2 978-32786193-10
result:
ok 10 lines
Test #13:
score: 0
Accepted
time: 0ms
memory: 18712kb
input:
10 248-746984-6 50-140-8997-6 96-8-622617-6 58-213-48056 03497-12-026 3712-885946 319-8564-506 2-3-62643476 756359-764-6 582-97771-2-6
output:
978-248-746984-6 978-50-140-8997-5 978-96-8-622617-1 978-58-213-48050 978-03497-12-024 978-3712-885943 978-319-8564-509 978-2-3-62643477 978-756359-764-2 978-582-97771-2-8
result:
ok 10 lines
Test #14:
score: 0
Accepted
time: 0ms
memory: 18572kb
input:
10 9703497217 3414631237 559383597-7 4545227287 72344-0-2667 741-7414567 91752-4984-7 0545975867 1-817640097 4073-3-5268-7
output:
978-9703497218 978-3414631237 978-559383597-0 978-4545227283 978-72344-0-2664 978-741-7414569 978-91752-4984-1 978-0545975865 978-1-817640092 978-4073-3-5268-6
result:
ok 10 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 18716kb
input:
10 30-6751714-8 720022041-8 8122-182-348 45-98765-20-8 387750-0048 51371-962-58 0-547777-418 2248735448 78-89-298978 6-16533168-8
output:
978-30-6751714-8 978-720022041-4 978-8122-182-347 978-45-98765-20-6 978-387750-0040 978-51371-962-53 978-0-547777-412 978-2248735449 978-78-89-298971 978-6-16533168-5
result:
ok 10 lines
Test #16:
score: 0
Accepted
time: 0ms
memory: 18664kb
input:
10 3863994019 1-883158419 40-88994949 56-6-201673-9 6-694343-779 52745031-79 0-243850-99-9 78-31645799 0677183259 2874-587109
output:
978-3863994013 978-1-883158415 978-40-88994949 978-56-6-201673-6 978-6-694343-777 978-52745031-74 978-0-243850-99-0 978-78-31645792 978-0677183251 978-2874-587108
result:
ok 10 lines
Test #17:
score: 0
Accepted
time: 0ms
memory: 18832kb
input:
10 407303295X 9-475-98657-X 827-522618-X 280455564X 1975-7120-3X 758-256152-X 090330614X 271696-6-63X 534942744X 53628-6680X
output:
978-4073032953 978-9-475-98657-6 978-827-522618-9 978-2804555641 978-1975-7120-37 978-758-256152-5 978-0903306140 978-271696-6-634 978-5349427442 978-53628-66808
result:
ok 10 lines