QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#876274 | #7698. ISBN Conversion | WeaRD276# | RE | 0ms | 3712kb | C++20 | 2.2kb | 2025-01-30 19:24:56 | 2025-01-30 19:24:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
int solve()
{
string s;
if (!(cin >> s))
return 1;
int n = sz(s);
if (s[0] == '-' || s.back() == '-')
{
cout << "invalid\n";
return 0;
}
int cnt = s[0] == '-';
FOR (i, 1, n)
{
cnt += s[i] == '-';
if (s[i] == '-' && s[i - 1] == '-')
{
cout << "invalid\n";
return 0;
}
}
if (cnt == 3 && s[n - 2] != '-')
{
cout << "invalid\n";
return 0;
}
ll sm = 0;
string ns = "";
FOR (i, 0, n)
if (s[i] != '-')
ns += s[i];
string ans = s;
s.swap(ns);
n = sz(s);
assert(n == 10);
FOR (i, 0, n)
{
ll cr = 10;
if (s[i] != 'X')
cr = s[i] - '0';
sm += cr * (10 - i);
}
if (sm % 11)
{
cout << "invalid\n";
return 0;
}
ans = "978-" + ans;
ans.pop_back();
ns = "";
FOR (i, 0, sz(ans))
if (ans[i] != '-')
ns += ans[i];
ll smm = 0;
assert(sz(ns) == 12);
FOR (i, 0, sz(ns))
{
if (i & 1)
{
smm += 3 * (ns[i] - '0');
}
else
{
smm += (ns[i] - '0');
}
}
int add = 0;
while (smm % 10)
{
smm += 1;
add++;
}
ans += to_string(add);
cout << ans << '\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cerr << "_____________________________\n";
#endif
}
#ifdef ONPC
cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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
Runtime Error
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-...