50分求助

P1055 [NOIP2008 普及组] ISBN 号码

H_C_Y_106 @ 2023-05-07 22:59:51


#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin >>a;
    int num=(a[0]-'0')*1+(a[2]-'0')*2+(a[3]-'0')*3+(a[4]-'0')*4+(a[6]-'0')*5+(a[7]-'0')*6+(a[8]-'0')*7+(a[9]-'0')*8+(a[10]-'0')*9;
    num%=11;
    if(a[12]-'0'==num){
        cout<<"Right";
    }
    else{
        a[12]=num+'0';
        cout<<a;
    }
    return 0;
}

by H_C_Y_106 @ 2023-05-07 23:00:17

错的是4、5、6、7、9


by BobPang @ 2023-05-07 23:22:48

识别码可能不是数字


by BobPang @ 2023-05-07 23:23:07

@SHMetro_OpenBVE


by SCP5543 @ 2023-05-14 09:26:54

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[14],c;
    cin>>s;
    int h=0,k=0;
    for(int i=0;i<11;i++)
    {
        if(s[i]!='-')
        {
            k++;
            h+=k*(s[i]-'0');
        }
    }
    h%=11;
    if(h==10) c='X';
    else c=h+'0';
    if(c==s[12]) cout<<"Right"<<endl;
    else
    {
        s[12]=c;
        cout<<s;
    }
    return 0;
}

|