求助

P1055 [NOIP2008 普及组] ISBN 号码

shaddock_qwq @ 2021-11-27 09:53:34

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[13];
    int f=0;

    cin>>s;

    f+=(s[0]*1-'0');
    f+=(s[2]*2-'0');
    f+=(s[3]*3-'0');
    f+=(s[4]*4-'0');
    f+=(s[6]*5-'0');
    f+=(s[7]*6-'0');
    f+=(s[8]*7-'0');
    f+=(s[9]*8-'0');
    f+=(s[10]*9-'0');

    f%=11;

    if(s[12]-'0'==f)
    {
        cout<<"Right";
    }
    else
    {
        for(int i=0;i<12;i++)
        {
            cout<<s[i];
        }
        if(f==10)
        {
            cout<<"X";
        }
        else
        {
            cout<<f;
        }
    }
    return 0;
}
//1 5 11

by TLE_Forever @ 2021-11-27 09:58:07

    f+=(s[0]*1-'0');
    f+=(s[2]*2-'0');
    f+=(s[3]*3-'0');
    f+=(s[4]*4-'0');
    f+=(s[6]*5-'0');
    f+=(s[7]*6-'0');
    f+=(s[8]*7-'0');
    f+=(s[9]*8-'0');
    f+=(s[10]*9-'0');

-'0'*吧?


by TLE_Forever @ 2021-11-27 10:00:44

@logic_dxr

s[10]*9-'0'中,假设s[10]='9',则s[10]*9-'0'=(9+'0')*9-'0'=81+'0'*8


by TLE_Forever @ 2021-11-27 10:02:24

    f%=11;

    if(s[12]-'0'==f)
    {
        cout<<"Right";
    }

还有这里应该没有判断余数为10也就是's[12]='X'的情况吧?


|