80分,第四个和第七个点出错了,求助

P1055 [NOIP2008 普及组] ISBN 号码

bbluele @ 2023-07-20 17:14:38

#include<iostream>
#include<string>
using namespace std;
string s;
int i, j[9], m, n, a;
int main()
{
    getline(cin, s);
    for (i = 0,n=0; i < 11; i++)
    {
        if (i == 1 || i == 5)continue;
        j[n] = s[i];
        n++;
    }
    for (i = 0; i < 9; i++)
    {
        m = (j[i]-48) * (i+1) + m;
    }
    a = m - (m / 11) * 11;
    if (s[12] == a+48)
        cout << "Right" << endl;
    else
    {
        if (a != 10)
            s[12] = a + 48;
        else
            s[12] = 'X';
        cout << s << endl;
    }
}

by 编码落寞 @ 2023-07-20 17:40:39

@bbluele 缺少判断原字符串最后一位为X的情况


|