文章

20

粉丝

146

获赞

10

访问

41.8k

头像
身份证校验 题解:
P1722 北京理工大学2017年机试题
发布于2024年2月6日 21:35
阅读数 535

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int weight[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    string s;
    while (cin >> s)
    {
        if (s.size() != 18)
        {
            cout << "ID Wrong" << endl;
            continue;
        }
        char y[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
        int sum = 0, x = 0;
        for (int i = 0; i < s.size() - 1; i++)
        {
            sum += ((s[i] - '0') * weight[i]);
        }
        x = sum % 11;
        if (y[x] != s[s.size() - 1])
        {
            cout << "ID Wrong" << endl;
        }
        else
        {
            cout << "ID Corrent" << endl;
        }
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发