题解 | #[NOIP2008]ISBN号码#

[NOIP2008]ISBN号码

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

#include <stdio.h>
#include <string.h>

int main()
{
    char s[15];

    scanf("%s", s);

    int ans = 0;
    int len = strlen(s);
    if (s[len - 1] == 'X') ans = 10;
    else ans = s[len - 1] - '0';

    int res = 0;
    for (int i = 0, j = 1; i < len - 2; i ++ )
    {
        if (s[i] != '-')
        {
            res = res + (s[i] - '0') * j;
            j ++ ;
        }
    }

    if (res % 11 == ans) printf("Right\n");
    else
    {
        if (res % 11 != 10) {
            s[len - 1] = (res % 11) + '0';
        }
        else s[len - 1] = 'X';
        
        for (int i = 0 ; i < len; i ++ ) printf("%c", s[i]);
    }

    return 0;
}

全部评论

相关推荐

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