请问哪里错了?只得了80分

P1055 [NOIP2008 普及组] ISBN 号码

nuoxi6868 @ 2023-08-17 16:56:30


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

by ZhuZining_king @ 2023-08-18 09:58:37

#include<bits/stdc++.h>
using namespace std;
string s;
int t=1;
long long sum;
int main(){
    cin>>s;
    for(int i=0;i<12;i++){
        if(s[i]-'0'>=0&&s[i]-'0'<=9){
            sum+=(s[i]-'0')*t;
            t++;
        }
    }
    sum=sum%11;
    if(sum==10){
        if(s[12]=='X')
            cout<<"Right";
        else{
            for(int i=0;i<12;i++)
                cout<<s[i];
            cout<<'X';
        }
    }
    else{
        if(s[12]-'0'==sum)
            cout<<"Right";
        else{
            for(int i=0;i<12;i++)
                cout<<s[i];
            cout<<sum;
        }
    }
    return 0;
}

by Rosy1 @ 2023-08-19 20:02:55

不能暴力枚举吧


|