10分求助

P1055 [NOIP2008 普及组] ISBN 号码

qiaodou @ 2025-01-08 20:53:41

#include<bits/stdc++.h>
using namespace std;
int main(){
    char isbn[11],yanzheng;
    scanf("%c-%c%c%c-%c%c%c%c%c-%c",&isbn[1],&isbn[2],&isbn[3],&isbn[4],&isbn[5],&isbn[6],&isbn[7],&isbn[8],&isbn[9],&yanzheng);
    int yanzheng2;
    char yanzheng2_c;
    for(int i=1;i<=9;i++){
        yanzheng2 += (i*(isbn[i]-'0'));
    }
    yanzheng2 %= 11;
    if(yanzheng2 == 10) yanzheng2_c='X';
    else yanzheng2_c = yanzheng2+'0';
    if(yanzheng==yanzheng2_c){
        printf("Right");
        return 0;
    }
    else printf("%c-%c%c%c-%c%c%c%c%c-%c",isbn[1],isbn[2],isbn[3],isbn[4],isbn[5],isbn[6],isbn[7],isbn[8],isbn[9],yanzheng2_c);
    return 0;
}

|