50pts 求助!!!!!!!!!!!!!!!!!!!!!!!!!

P1055 [NOIP2008 普及组] ISBN 号码

细数繁星 @ 2023-04-01 11:15:34

RT

@OJone, @Liumingxuan2010,

#include<cstdio>
#include<cmath>

int main()
{
    int a, b, c, record;
    scanf("%d-%d-%d-%s", &a, &b, &c, &record);
    // printf("%d", record);

    if (record == 'X')
    {
        record = 10;
    }
    else if (record >= '0')
    {
        record -= '0';
    }

    int result = a * 100000000 + b * 100000 + c;
    int len = (int) log10(result) + 1;
    int sum = 0;
    int total = len;
    for (int i = 1; i < len; i++)
    {
        sum += (result / (int)(pow(10.0, len - i - 1)) % 10)
        * (i + 2);

        // printf("%d %d\n", (result / (int)(pow(10.0, len - i - 1)) % 10), i + 2);
    }
    // printf("%d\n", sum);

    int recordpd = result % 11;
    if (recordpd == record)
    {
        printf("%s\n", "Right");
        return 0;
    }
    else
    {
        if (recordpd < 10)
        {
            printf("%d-%d-%d-%d", a, b, c, recordpd);
        }
        else
        {
            printf("%d-%d-%d-%s", a, b, c, "X");
        }
    }
    return 0;
}

by Andy_Li @ 2023-04-02 20:51:37

@Liumingxuan2010 你可能不明白什么叫做调码吧,点开看看就知道了


上一页 |