90分求助大佬!!!

P1055 [NOIP2008 普及组] ISBN 号码

duan1zhuo @ 2023-08-19 23:01:08

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    char j;
    scanf("%d-%d-%d-%c",&a,&b,&c,&j);
    if(j=='X') j=10;
    int b1=b/100,b2=b%100/10,b3=b%10;
    int c1=c/10000,c2=c%10000/1000,c3=c%1000/100,c4=c%100/10,c5=c%10;
    int x=a*1+b1*2+b2*3+b3*4+c1*5+c2*6+c3*7+c4*8+c5*9;
    int e=x%11;
    if(j==e){
        cout<<"Right";
    }
    else{
        printf("%d-%d-%d-",a,b,c);
        if(e==10) cout<<"X";
        else cout<<e;
    }
}

1 WA


by yizongyuan @ 2023-08-19 23:23:28

AC代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,j2;
    char j;
    scanf("%d-%d-%d-%c",&a,&b,&c,&j);
    if(j=='X') j2=10;
    else{
        j2=j-48;
    }
    //j是char类型的,需要转换成int 
    int b1=b/100,b2=b%100/10,b3=b%10;
    int c1=c/10000,c2=c%10000/1000,c3=c%1000/100,c4=c%100/10,c5=c%10;
    int x=a*1+b1*2+b2*3+b3*4+c1*5+c2*6+c3*7+c4*8+c5*9;
    int e=x%11;
    if(j2==e){
        cout<<"Right";
    }
    else{
        printf("%d-%d-%d-",a,b,c);
        if(e==10) cout<<"X";
        else cout<<e;
    }
}

|