#80分求救

P1055 [NOIP2008 普及组] ISBN 号码

jieqiang @ 2022-01-14 17:29:33


#include<iostream>
using namespace std;
int main()
{
    char s[13];
    for (int i = 0; i < 13; i++)
    {
        cin >> s[i];
    }
    int m = 0;
    for (int i = 0,j=1; i < 11; i++)
    {
        if (s[i] == '-')
        continue;
        m += (s[i] - '0') * j;
        j++;
    }
    if ((m % 11 == s[12]-'0') || (m % 11 == 10 && s[12] == 'x'))
    {
        cout << "Right";
    }
    else
    {
        if (m % 11 == 10)
            s[12] = 'X';
        else
            s[12] = m % 11 + '0';
        for (int i = 0; i < 13; i++)
        {
            cout << s[i];
        }
        //cout << s;
    }
}

|