为什么测试点5的ISBN码不对,用计算器都摁过了

P1055 [NOIP2008 普及组] ISBN 号码

rnf5114 @ 2023-02-06 16:46:36

qwq


by Loser_Syx @ 2023-02-06 17:14:59

@liyong5114 请贴代码


by rnf5114 @ 2023-02-06 17:50:46

@Saint_ying_xtf 新用户,不会贴


by rnf5114 @ 2023-02-06 18:09:07

#include <bits/stdc++.h>
using namespace std;
int main(){
    int s,s1=1,d;
    char a[14];
    for(int i=0;i<=12;i++){
        cin>>a[i];
        if(a[i]!='-'&&i!=12){
            d=(a[i]-'0')*s1;
            s+=d;
            s1++;
        }
    }
    if(a[12]>='0'&&a[12]<='9'){
        if(s%11==a[12]-'0'){
            cout<<"Right";
        }
        else{
            for(int i=0;i<=11;i++){
                cout<<a[i];
            }
            cout<<s%11;
        }
    }
    else if(a[12]=='X'){
        if(s%11==10){
            cout<<"Right";
        }
        else{
            for(int i=0;i<=11;i++){
                cout<<a[i];
            }
            cout<<s%11;
        }
    }

    return 0;
}

by rnf5114 @ 2023-02-06 18:10:09

@Saint_ying_xtf 贴好了


by Loser_Syx @ 2023-02-06 18:11:55

@liyong5114 最后如果s%11是10的话不就错了吗,要输出X


by rnf5114 @ 2023-02-06 18:25:30

@Saint_ying_xtf 过了,感谢


|