文章

34

粉丝

67

获赞

7

访问

8.8k

头像
身份证校验 题解:c
P1722 北京理工大学2017年机试题
发布于2024年3月2日 17:51
阅读数 483

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

int main()
{
    char ch[20];
    int num[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    char cnt[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
    while (scanf("%s", ch) != EOF)
    {

        if (strlen(ch) != 18)
        {
            printf("ID Wrong\n");
        }
        else
        {
            int all = 0;
            for (int i = 0; i < 17; i++)
            {
                all += (ch[i] - '0') * num[i];
            }

            if (cnt[all % 11] == ch[17])
            {
                printf("ID Corrent\n");
            }
            else
            {
                printf("ID Wrong\n");
            }
        }
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发