谁能帮帮我

P1055 [NOIP2008 普及组] ISBN 号码

Xianyujunzhu @ 2024-05-17 18:05:35

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string mod="0123456789X";
    int ans=0,t=0;
    int n=1;
    getline(cin,s);
    for(int i=0;i<12;i++){
        if(s[i]=='-') continue;
        t+=(s[i]-'a')*n;
        n++;
    }
    if(mod[t%11]==s[12]) cout<<"Right";
    else{
        s[12]=mod[t%11];
        cout<<s;
    }
    return 0;
}

by wanglexi @ 2024-05-17 18:29:49

t+=(s[i]-'a')*n 不对.

这里要求的是 s[i]mod 里的第几个.

AC 代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string mod="0123456789X";
    int ans=0,t=0;
    int n=1;
    getline(cin,s);
    for(int i=0;i<12;i++){
        if(s[i]=='-') continue;
//      t+=(s[i]-'a')*n;
        for(int j=0;j<11;j++){
            if(mod[j]==s[i]){
                t+=j*n;
                break;
            }
        }
        n++;
    }
    if(mod[t%11]==s[12]) cout<<"Right";
    else{
        s[12]=mod[t%11];
        cout<<s;
    }
    return 0;
}

by wanglexi @ 2024-05-17 18:30:07

@Xianyujunzhu


|