题解 | #[NOIP2008]ISBN号码#

[NOIP2008]ISBN号码

https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5

#include <stdio.h>

int main()
{
    int lan = 0,pub=0,id=0;
    char PIN;
    scanf("%d-%d-%d-%c", &lan,&pub,&id,&PIN);
    int sum = 0,sum1=0,sum2=0;
    int pub1=pub,id1=id;
    int i = 0;
    //求pub的相加之和
    for (i = 4; i >= 2; i--)
    {
        sum += (pub % 10)*i;
        pub = pub/10;
    }
    for (i = 9; i >= 5; i--)
    {
        sum1 += (id % 10) * i;
        id = id/10;
    }
    sum2 = (lan * 1 + sum1 + sum)%11;
    while (sum2 == 10)
    {
        if (PIN=='X')
        {
            printf("Right");
            break;
        }
        else
        {
            PIN = 'X';
            printf("%d-%d-%d-%c", lan, pub1, id1, PIN);
            break;
        }
    }
    while (sum2 != 10)
    {
        if (sum2==(int)PIN-'0')
        {
            printf("Right");
            break;
        }
        else
        {
            printf("%d-%d-%d-%d", lan, pub1, id1, sum2);
            break;
        }
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务