帮忙看看哪里错了,谢谢大佬

P1055 [NOIP2008 普及组] ISBN 号码

Bary @ 2022-04-28 18:41:59

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

by Node_Edge @ 2022-04-28 19:09:47

@Bary

#include<iostream>
using namespace std;
int main()
{
    char a[20];
    int i,j=0;
    cin >> a;
    int check=0;

    for (i = 0; i <= 11; i++)
    {
        if (a[i] == '-')
        {
            continue;
        }
        check +=(a[i] - '0') * (j + 1);
        j++;
    }
    check %= 11;
    if (a[12] == 'X' && check == 10 || check == a[12] - '0')
    {
        cout << "Right";
    }
    else
    {
        for (i = 0; i <= 11; i++)
        {
            cout << a[i];
        }
        cout <<char( check == 10 ? 'X' : check+'0');
    }
}

|