为什么测试点输出都一样,但是过不了

P1055 [NOIP2008 普及组] ISBN 号码

kuxiaowo @ 2024-03-23 16:02:19

下了测试点,输出都一样,Right拼写也没错

#include<bits/stdc++.h>
using namespace std;
int main(){
    char ISBN[13];
    cin>>ISBN;
    int sh;
    for(int i=0, j=1;i<11;i++){
        if(i==1 || i==5) continue;
        sh+=(ISBN[i]-'0')*j;
        j++;
    }
    sh%=11;
    char b;
    if(sh == 10) b='X';
    else b=static_cast<char>(sh + '0');
    cout << b << "    " << ISBN[12] << endl; 
    if(b==ISBN[12]){
        cout<<"Right"<<endl;
    } else {
        for(int i=0;i<=11;i++){
            cout<<ISBN[i];
        }
        if(sh < 10) cout<<sh;
        else cout<<'X';
    }
    return 0;
} 

by Zebraj @ 2024-03-24 19:51:20

for(int i=0, j=1;i<11;i++)

改成

for(int i=0, j=1;i<11;i++)

还有

cout << b << "    " << ISBN[12] << endl;

不要


by Zebraj @ 2024-03-24 19:52:16

@zrj2012 写错了


by Zebraj @ 2024-03-24 19:53:08

@zrj2012

for(int i=0, j=1;i<11;i++)

改成

for(int i=0, j=1;i<12;i++)

by Zebraj @ 2024-03-24 19:55:46

@kuxiaowo 算了,看我代码吧。

#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;
}

就AC了


by Zebraj @ 2024-03-24 20:03:45

@kuxiaowo 懂我代码吧?


by Thomas_Alex @ 2024-03-26 00:10:03

还没过吗,不愧是西南最质量的班


by kuxiaowo @ 2024-03-29 12:20:15

@no_oier111 死人东西


|