90分求助

P1055 [NOIP2008 普及组] ISBN 号码

zhaoanqiEtayo @ 2023-07-09 14:41:47

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c,d,e,f,g,h,i,s;
    char j;
    scanf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%c",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
    s=1*a+2*b+3*c+4*d+5*e+6*f+7*g+8*h+9*i;
    if(s%11!=10)
    {
        if(s%11==j)
        {
            printf("Right");
         }    
        else
        {
            printf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%1d",a,b,c,d,e,f,g,h,i,s%11);    
        }
    }
    else
    {
        if(j=='X')
        {
             printf("Right");
        }
        else
        {
            printf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-X",a,b,c,d,e,f,g,h,i);    
        }
    }
    return 0;
}

90分求助


by zfj123456 @ 2023-07-09 15:05:20

@zhaoanqiEtayo 你的j是个char类型的 所以s%11==j是不合理的 要转化成int型比较 建议改为if(s%11==j-'0')


|