QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#807729#7698. ISBN Conversionucup-team3723#WA 0ms3632kbC++171.8kb2024-12-10 10:55:022024-12-10 10:55:04

Judging History

你现在查看的是最新测评结果

  • [2024-12-10 10:55:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2024-12-10 10:55:02]
  • 提交

answer

#include <bits/stdc++.h>
#define dbg(x) cerr << #x << ':' << (x) << endl; 
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()

int n;
string s;

void solve() {
    deque<int> hy,dig;
    for (int i = 0; i < n; ++i) {
        if (s[i]=='-') {
            hy.push_back(i);
        }
        else {
            dig.push_back((s[i]=='X' ? 10 : s[i] - '0'));
        }
    }
    bool ok = true;
    if (hy.size() > 3) {
        ok = false;
    }
    if (hy.size() >= 1 && hy.front() == 0) {
        ok = false;
    }
    if (hy.size() >= 1 && hy.back() == n-1) {
        ok = false;
    }
    for (int i = 0; i+1 < hy.size(); ++i) if (hy[i]+1 == hy[i+1]) {
        ok = false;
        break;
    }
    if (hy.size() == 3 && hy.back() != n-2) {
        ok = false;
    }
    if (dig.size() != 10) {
        ok = false;
    }
    if (ok) {
        int mod = 11;
        int sum = 0;
        for (int i = 0; i < 9; ++i) {
            sum += (10 - i) * dig[i];
        }
        sum %= mod;
        int cs = (mod - sum) % mod;
        if (dig.back() != cs) {
            ok = false;
        }
    }

    if (ok) {
        string ans = "978-" + s;
        ans.pop_back();
        dig.push_front(8);
        dig.push_front(7);
        dig.push_front(9);
        int mod = 10;
        int sum = 0;
        for (int i = 0; i < 12; ++i) {
            sum += (i % 2 == 0 ? 1 : 3) * dig[i];
        }
        sum %= mod;
        int cs = (mod - sum) % mod;
        ans.push_back(cs + '0');
        cout << ans << '\n';
    }
    else {
        cout << "invalid\n";
    }
}

int main()
{
    int t;
    cin >> t;
    while (t--) {
        cin >> s;
        n = s.size();
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

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: 3632kb

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
978-XXXXXXXXX2
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

wrong answer 5th lines differ - expected: 'invalid', found: '978-XXXXXXXXX2'