QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537655#7698. ISBN Conversionyzkkai#WA 0ms3828kbC++201.5kb2024-08-30 17:12:362024-08-30 17:12:37

Judging History

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

  • [2024-08-30 17:12:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-08-30 17:12:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
#define sz(x) signed(size(x))

void solve() {
    string s;
    cin >> s;
    int cnt = 0;
    int n = s.size();
    for(int i = 0;i < n;i ++){
        if(s[i] == '-'){
            cnt += 1;
            if(i == 0 || i == n-1){
                cout << "invalid\n";
                return ;
            }
            if(cnt == 3 && i != n-2){
                cout << "invalid\n";
                return;
            }
                
        }
        if(s[i] == 'X' && i != n-1){
            cout << "invalid\n";
            return ;
        }
    }
    if(cnt > 3 || n - cnt != 10){
        cout << "invalid\n";
        return;
    }
    
    cnt = 10;
    int sum = 0;
    for(char c : s){
        if(c != '-'){
            if(c == 'X')
                sum += 10 * cnt;
            else
                sum += (c - '0') * cnt;
            cnt -= 1;
        }
    }
    if(sum % 11){
        cout << "invalid\n";
        return ;
    }
    cnt = 0;
    s = "978-" + s;
    s.pop_back();
    n = s.size();
    sum = 0;
    for(int i = 0;i < n;i ++){
        if(s[i] != '-'){
            sum += (cnt % 2 == 0 ? 1 : 3) * (s[i] - '0');
            cnt += 1;
        }
    }
    cout << s << (10 - sum%10) % 10 << "\n";
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int 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: 0ms
memory: 3828kb

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

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
978-01--23456786
978-012345678--6
invalid
invalid
invalid
invalid
invalid
invalid

result:

wrong answer 18th lines differ - expected: 'invalid', found: '978-01--23456786'