真的不会了

P1055 [NOIP2008 普及组] ISBN 号码

cowboy666 @ 2022-12-15 13:38:20

大佬帮忙看看为什么只有50分

#include<string>
#include <iostream>
using namespace std;
int main()
{
    string a;
    cin >> a;
    int b = (a[0] - 48) * 1 + (a[2] - 48) * 2 + (a[3] - 48) * 3 + (a[4] - 48) * 4 + (a[6] - 48) * 5 + (a[7] - 48) * 6 + (a[8] - 48) * 7 + (a[9] - 48) * 8 + (a[10] - 48) * 9;
    if (b % 11 == (a[12] - 48))cout << "Right" << endl;
    else
    {
        a[12] = b % 11 + 48;
        cout << a << endl;
    }
    return 0;
}

by ZQIN_P @ 2022-12-15 13:43:27

你忘记特判%11=10的情况了


by ZQIN_P @ 2022-12-15 13:43:55

@cowboy666


by ZQIN_P @ 2022-12-15 13:46:39

#include<string>
#include <iostream>
using namespace std;
int main()
{
    string a;
    cin >> a;
    int b = (a[0] - 48) * 1 + (a[2] - 48) * 2 + (a[3] - 48) * 3 + (a[4] - 48) * 4 + (a[6] - 48) * 5 + (a[7] - 48) * 6 + (a[8] - 48) * 7 + (a[9] - 48) * 8 + (a[10] - 48) * 9;
    if (b % 11 <= 10){
        if (b % 11 == (a[12] - 48))cout << "Right" << endl;
        else
        {
            a[12] = b % 11 + 48;
            cout << a << endl;
        }
    }
    else
    {
        if(a[12] == 'x')cout << "Right" << endl;
        else a[12] = 'x';
    }

    return 0;
}

by ZQIN_P @ 2022-12-15 13:47:29

建议把输出移到外面,我忘记改了,你自己改一下吧


by cowboy666 @ 2022-12-15 13:49:29

@planet_over_for_ever 哇,感谢大佬666,这一指点让我茅塞顿开,五雷轰顶!!!!!


by ZQIN_P @ 2022-12-15 13:50:34

@cowboy666 不谢,助人为乐嘛


by __er @ 2022-12-15 14:12:44

乐,中二人


|