90分求助
查看原帖
90分求助
1287110
145a楼主2024/2/25 19:23

555就差第一个WA其他都AC了

#include <iostream>

#include <string>

using namespace std;

int main()

{

    string isbn, isbnWithoutIdCode;

    char testIdCode;

    int index = 1, idCodeCount = 0;

    getline(cin, isbn);

    isbnWithoutIdCode = isbn.substr(0, 11);

    testIdCode = isbn.at(12);

    for (char &currentChar: isbn.substr(0, 11))

    {

        if (currentChar == '-') continue;

        int currentNum = currentChar - '0';

        idCodeCount += index * currentNum;

        index += 1;

    }

    idCodeCount %= 11;

    if (idCodeCount == 10)

    {

        cout << (testIdCode == 'X' ? "Right" : isbnWithoutIdCode + "-X");

    }

    else

    {

        cout << (testIdCode == idCodeCount ? "Right" : isbnWithoutIdCode + "-" + to_string(idCodeCount));

    }

}
2024/2/25 19:23
加载中...