求助大佬 C语言 80分4号点和7号点WA

P1055 [NOIP2008 普及组] ISBN 号码

enderLilisi @ 2023-10-24 22:39:36

#include<stdio.h>
int main()
{
    int  a = 0;
    int b = 0;
    int c = 0;
    char d = 0;
    int x = 0, y = 0, z = 0;
    int sum1=0,sum2=0,sum3 = 0;
    scanf("%d-%d-%d-%c", &a, &b, &c, &d);
    int num1 = a, num2 = b, num3 = c;
    sum1 = a * 1;
    y = 4;
    for (int i=0;i<3;i++)
    {
        x = b % 10;
        sum2 = sum2 + x * y;
        y--;
        b=b / 10;
    }//用来计算第二部分的和
    z = 9;
    for (int i = 0; i < 5; i++)
    {
        x = c % 10;
        sum3 = sum3 + x * z;
        z--;
        c=c / 10;
    }//用来计算第三部分的和
    x = (sum1 + sum2 + sum3)%11;
    y = (int)d - 48;
    d = y+48;
    if (x == y)
    {
        printf("Right");
    }
    else
    {
        if (x< 10)
            d = x + 48;
        else
            d = 88;
        printf("%d-%d-%d-%c", num1, num2, num3,d);
    }
    return 0;
}

by lxwilm @ 2023-11-10 01:02:47

俺也一样(4、7)


by Lych233 @ 2023-11-16 16:55:16

注意识别码中存在'X'

没有注意对‘X’的判断就会在4号点和7号点WA


|