QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#676960 | #7698. ISBN Conversion | new_game_plus_players# | WA | 0ms | 3596kb | C++14 | 1022b | 2024-10-26 06:34:12 | 2024-10-26 06:34:13 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
bool solve() {
string s;
cin>>s;
vector<int> h, v;
for (int i=0; i<s.size(); i++) {
if (s[i]=='-') {
h.PB(i);
} else {
v.PB(s[i]=='X' ? 10 : s[i]-'0');
}
if (s[i]=='X' && i+1 < s.size()) return false;
}
if (h.size() > 3) return false;
if (h.size()==3 && h[2] != s.size()-2) return false;
for (int i=1; i<h.size(); i++) {
if (h[i-1] + 1 == h[i]) return false;
}
if (v.size() != 10) return false;
int sum = 0;
for (int i=0; i<10; i++) {
sum += (10-i) * v[i];
}
if (sum%11 != 0) return false;
sum = 9 + 7 * 3 + 8;
for (int i=0; i<9; i++) {
sum += (3 - (i%2)*2) * v[i];
}
int cs = 10 - sum % 10;
string t = "978-";
t = t + s;
t[t.size()-1] = '0' + cs;
cout<<t<<endl;
return true;
}
int main() {
int Tn;
cin>>Tn;
while (Tn--) {
if (!solve()) {
puts("invalid");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 3568kb
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 978--01234567896 978-01234567896 978--0123456786 invalid invalid invalid invalid invalid invalid invalid invalid
result:
wrong answer 15th lines differ - expected: 'invalid', found: '978--01234567896'