再次求助

P1055 [NOIP2008 普及组] ISBN 号码

li_zhi_a_wei @ 2023-08-16 11:19:02

#include <iostream>
using namespace std;
char a[14];
int main(){
    for(int i=0;i<=12;i++){
        cin >>a[i];
    }
    long long j=(a[0]-'0')*1+(a[2]-'0')*2+(a[3]-'0')*3+(a[4]-'0')*4+(a[6]-'0')*5+(a[7]-'0')*6+(a[8]-'0')*7+(a[9]-'0')*8+(a[10]-'0')*9;
    j%=11;
    if(j==a[12]-'0'){
        cout <<"Right";
        return 0;
    }
    a[12]=j+'0';
    for(int i=0;i<=12;i++){
        cout<<a[i];
    }
    return 0;
    cout <<a[12]; 
}

by li_zhi_a_wei @ 2023-08-16 11:19:45

50分


by xvl_ @ 2023-08-16 11:29:58

@MENGw

如果最后一位是 X 呢


by xvl_ @ 2023-08-16 11:31:17

@MENGw

#include <iostream>
using namespace std;
char a[14];
int main(){
    for(int i=0;i<=12;i++){
        cin >>a[i];
    }
    long long j=(a[0]-'0')*1+(a[2]-'0')*2+(a[3]-'0')*3+(a[4]-'0')*4+(a[6]-'0')*5+(a[7]-'0')*6+(a[8]-'0')*7+(a[9]-'0')*8+(a[10]-'0')*9;
    j%=11;
    if((j==a[12]-'0')||(j == 10&&a[12]=='X')){
        cout <<"Right";
        return 0;
    }
    if(j==10)a[12]='X';
    else a[12]=j+'0';
    for(int i=0;i<=12;i++){
        cout<<a[i];
    }

    return 0;
}

这样即可 AC


by li_zhi_a_wei @ 2023-08-16 11:36:42

@xvl_ 感谢感谢 已经关注


|