求助

P1055 [NOIP2008 普及组] ISBN 号码

Maxuejun @ 2023-04-30 22:30:17

#include<bits/stdc++.h>
using namespace std;
char a[20];
int b[15];
int main(){
    cin>>a;
    int j=0,ans=0,n=strlen(a);
    for(int i=0;i<n;i++){
        if(a[i]>='0'&&a[i]<='9'){
            b[j]=a[i]-'0';
            j++;
        }
    }
    for(int i=0;i<j-1;i++){
        ans+=b[i]*(i+1);
    }
    if(ans%11==b[j-1]){
        cout<<"Right";
        return 0;
    }
    else{
        if(ans%11==10&&b[j-1]=='X'){
            cout<<"Right";
            return 0;
        }
        for(int i=0;i<n-1;i++){
            cout<<a[i];
        }
        if(ans%11==10){
            cout<<"X";
        }
        else{
            cout<<ans%11;
        }
    }
    return 0;
}

by xiaoshumiao @ 2023-05-30 17:45:09

if(ans%11==b[j-1]){
    cout<<"Right";
    return 0;
}
else{
    if(ans%11==10&&b[j-1]=='X'){
        cout<<"Right";
        return 0;
    }

这里不对,应该为:

if(ans%11==(b[n-1]-'0')){
    cout<<"Right";
    return 0;
}
else{
    if(ans%11==10&&b[n-1]=='X'){
        cout<<"Right";
        return 0;
    }

|