zoukankan      html  css  js  c++  java
  • SDNU 1277.严厉打击假冒身份证

    Description

    WY最近从网上学来了如何验证正确的身份证的方法,有了这个方法,WY天黑都不怕~~

    已知身份证验证方法如下:
    根据〖中华人民共和国国家标准 GB 11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。
    1.将前面的身份证号码17位数分别乘以不同的系数。身份证号码第i位对应的系数为[2^(18-i)] mod 11(此处^代表指数运算)。
    2.将这17位数字和系数相乘的结果相加
    3.用加出来和除以11,得出余数y。
    4.校验码为(12 - y) mod 11 若此结果为10,则以小写字母x代替。

    Input

    多行身份证号

    Output

    输出该身份证是否合法,合法输出"Right",不合法输出"Error",后边跟一空白行

    Sample Input

    111111199801010017

    Sample Output

    Right
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    
    #define ll long long
    
    int plu[20];
    ll sum1;
    string word;
    char c;
    
    int qsm(int a, int b)//快速幂
    {
        int sum = 1;
        while(b)
        {
            if(b&1)
            {
                sum = (sum*a)%11;
            }
            b /= 2;
            a = (a*a)%11;
        }
        return sum;
    }
    
    int main()
    {
        for(int i = 0; i <= 17; i++)
        {
            plu[i] = qsm(2, 17-i);
        }
        while(cin >> word)
        {
            sum1 = 0;
            for(int i = 0; i<17; i++)
            {
                sum1 += (word[i]-'0')*plu[i];
            }
            int miao = (12-(sum1%11))%11;
            if(miao == 10)
            {
                if(word[17] == 'x')printf("Right
    
    ");
                else printf("Error
    
    ");
            }
            else
            {
                if(miao == word[17]-'0')printf("Right
    
    ");
                else printf("Error
    
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    [HNOI2002]营业额统计
    HDU 1374
    HDU 3345
    HDU 2089
    Graham扫描法
    Codeforces 1144D Deduction Queries 并查集
    Codeforces 916E Jamie and Tree 线段树
    Codeforces 1167F Scalar Queries 树状数组
    Codeforces 1167E Range Deleting
    Codeforces 749E Inversions After Shuffle 树状数组 + 数学期望
  • 原文地址:https://www.cnblogs.com/RootVount/p/10365734.html
Copyright © 2011-2022 走看看