QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749651 | #7698. ISBN Conversion | alexhamidi | WA | 0ms | 3736kb | C++14 | 1.6kb | 2024-11-15 08:48:07 | 2024-11-15 08:48:08 |
Judging History
answer
#include <iostream>
using namespace std;
bool isValid(string ups) {
string s = "";
if (ups.back() == '-' || ups.front() == '-') {
return false;
}
int numH = 0;
bool prevH = false;
for (char c : ups) {
if (c=='-') {
if (prevH) {
return false;
}
numH++;
prevH = true;
} else {
prevH = false;
s.push_back(c);
}
}
if (s.size() != 10) {
return false;
}
if (numH > 3) {
return false;
}
if (numH == 3 && ups[ups.size()-2] != '-') { //here is where we fail
return false;
}
int S = 0;
for (int i = 0; i < 9; i++) {
S += (10-i) * (s[i]-'0');
}
S += s.back() == 'X' ? 10 : s.back() - '0';
cout << S << "\n";
return (S%11==0);
}
string convert(string ups) {
string ans = "978-" + ups;
int pre = 38;
bool three = true;
for (int i = 0; i < ups.size()-1;i++) {
char c = ups[i];
if (c != '-') {
int val = c-'0';
if (three) {
pre += 3*val;
} else {
pre += val;
}
three = !three;
}
}
ans.back() = (10 - (pre%10))+'0';
return ans;
}
int main() {
string out = "";
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
if (isValid(s)) {
out += convert(s) + "\n";
} else {
out += "invalid\n";
}
}
cout << out;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3736kb
input:
4 3-540-4258-02 039428013X 3-540-42580-2 0-14-028333-3
output:
198 187 123 invalid 978-0394280134 978-3-540-42580-9 invalid
result:
wrong answer 1st lines differ - expected: 'invalid', found: '198'