为什么过不了求助

P1055 [NOIP2008 普及组] ISBN 号码

kick13times @ 2021-11-04 20:02:16

#include<iostream>
#include<string>
using namespace std;
int main(){
    char BOOK[14];
    int a,n=1,result,i;
    cin>>BOOK;
    for(i=0;i<13;i++){
        if(BOOK[i]=='-'){
            continue;
        }
        int BOOK[i];
        result+=(BOOK[i]-'0')*n-'0';
        n++;
    }
    if(result%11==BOOK[14]){
        cout<<"Right"<<endl;
    }else if(result%11==10){
        if(BOOK[13]=='X'){
            cout<<"Right"<<endl;
        }else{
            cout<<BOOK[13];
        }
    }else{
        cout<<BOOK[13];
    }
    return 0;

}

by xejwsy @ 2021-11-04 20:09:59

没有输出啊


by xiongjunxiang @ 2021-11-04 20:15:34

完全不对啊


by xejwsy @ 2021-11-04 20:21:28

修改后code如下


by xejwsy @ 2021-11-04 20:21:46

#include<iostream>
#include<string>
using namespace std;
int main(){
    string BOOK;
    int a,n = 1,result = 0;
    cin >> BOOK;
    for(int i = 0; i < 12; i++){
        if(BOOK[i] == '-'){
            continue;
        }
        //int BOOK[i];
        result += (BOOK[i]-'0')*n;
        n++;
    }
    if(BOOK[12]-'0'==result%11){
        cout<<"Right"<<endl;
    }else if(result%11==10){
        if(BOOK[12] == 'X'){
            cout<<"Right"<<endl;
            return 0;
        }else{
            //cout<<BOOK[13];
            BOOK[12] = 'X';
            cout << BOOK;
        }
    }else{
        //cout<<BOOK[13];
        BOOK[12] = (result%11)+'0';
        cout << BOOK;
    }
    return 0;

}

by xejwsy @ 2021-11-04 20:23:22

@kick13times 注意读题,字符串操作和输出!!!

+'0',-'0'别混淆!!!


by kick13times @ 2021-11-04 20:23:56

懂了,谢谢你!太感谢了


by xejwsy @ 2021-11-04 20:30:29

我是小学生,一起加油!


by kick13times @ 2021-11-04 20:36:45

@xejwsy 再次感谢orz


by xejwsy @ 2021-11-04 20:39:54

我头一回听到别人叫我orz,呜呜


|