QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749654#7698. ISBN ConversionalexhamidiWA 0ms3832kbC++141.6kb2024-11-15 08:50:482024-11-15 08:50:49

Judging History

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

  • [2024-11-15 08:50:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-11-15 08:50:48]
  • 提交

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';
    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;
}

Details

Tip: Click on the bar to expand more detailed information

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: 0
Accepted
time: 0ms
memory: 3604kb

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

result:

ok 25 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

5
71234567X1
71234567X-1
2-2345678-9
8X-7X-123456
7123X8123X

output:

invalid
invalid
invalid
invalid
invalid

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

10
3-540-42580-X
3-540-42580-3
0393609394
0-19-853453-9
0070131510
0070131512
0070131514
0070131516
0070131518
007013151X

output:

invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

11
767-13423100
65955-01-15-1
778592-4222
3283-138-073
8-802896-37-4
514-2481525
356-52708-6-6
4-810-73599-7
3-28438-244-8
1-98-2031209
82-54-55344X

output:

invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

ok 11 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

12
0123456789
0-19-853453-1
0070131511
0-07-0131511
039428013-X
0-39-428013X
0-3942801-3X
0131103628
3-540-42580-2
3540425802
1535956828
1535-9-5682-8

output:

978-0123456786
978-0-19-853453-2
978-0070131514
978-0-07-0131514
978-039428013-4
978-0-39-4280134
978-0-3942801-34
978-0131103627
978-3-540-42580-9
978-3540425809
978-1535956826
978-1535-9-5682-6

result:

ok 12 lines

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

10
69289-01810
07-8-2406750
4946302-980
91-45-00652-0
2526831830
8370591930
022-18967-4-0
86340-22-25-0
862-57-6642-0
1691783730

output:

978-69289-0181:
978-07-8-2406757
978-4946302-985
978-91-45-00652-8
978-2526831832
978-8370591939
978-022-18967-4-3
978-86340-22-25-4
978-862-57-6642-6
978-1691783731

result:

wrong answer 1st lines differ - expected: '978-69289-01810', found: '978-69289-0181:'