80分,#4#7wa了,求助大佬!

P1055 [NOIP2008 普及组] ISBN 号码

acmwriter @ 2022-10-07 22:37:47

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

by yingbowen @ 2022-10-07 22:44:39

@acmwriter 没有特判输入的识别码就是X的情况


by yingbowen @ 2022-10-07 22:46:07

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

这样就能A了


by yingbowen @ 2022-10-07 22:48:28

希望对你有所帮助


by acmwriter @ 2022-10-08 14:51:01

@yingbowen 感谢大佬!


|