Describe:
China's national standard GB 11643-1999〗: The citizenship number is a 18-bit feature combination code, consisting of 17-bit digital body code and a digit check code. The sorting order is from left to right: six-digit address code, eight-digit birth date code, three-digit sequential code, and one-digit check code. The verification code (the last one) the calculation method and the steps are: (1) 17-bit digital body Code Weighted summation Formula S = Sum (Ai * Wi), i = 0, ..., 16, the first 17 digits of the sum of the right of the Ai: represents the position of the ID number of the number value Wi: Indicates the position of the weighted factor 17-bit weighting factors from left to right are Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 (2) modulo y = mod (S, 11) (3) Check the table by modulo y to get the corresponding check code
| Y |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
| Check code |
1 |
0 |
X |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
For example, the first 17 digits of an identity card are 11010519491231002
| |
8 |
|
|
15 |
| |
1 |
|
9 |
5 |
| |
1 |
|
1 |
|
0 |
| Product |
7 |
9 |
0 |
5 |
0 |
20 |
2 |
9 |
24 |
27 |
7 |
18 |
30 |
5 |
0 |
0 |
4 |
The obtained sum is: 167; the model is y=167%11=2 (3) Check code is x (uppercase) Please follow the steps described above, enter a second-generation ID number, check whether the ID card is correct. Input: Enter several lines, one ID number per line, and the last line input-1 output: The output 1 is correct, and 0 represents the wrong input:
120223198902021249130132199210293822130402198207290622-1
Output
1
1
0
1#include <iostream>2#include <string>3 using namespacestd;4 5 intCalstringa)6 {7 return(a[0] -'0') *7+ (a[1] -'0') *9+ (a[2] -'0') *Ten+ (a[3] -'0') *5+ (a[4] -'0') *8+ (a[5] -'0') *4+ (a[6] -'0') *2+ (a[7] -'0') *1+ (a[8] -'0') *6+ (a[9] -'0') *3+ (a[Ten] -'0') *7+ (a[ One] -'0') *9+ (a[ A] -'0') *Ten+ (a[ -] -'0') *5+ (a[ -] -'0') *8+ (a[ the] -'0') *4+ (a[ -] -'0') *2;8 }9 Ten CharSstringa) One { A intK = Cal (a)% One; - if(k = =0) - return '1'; the Else if(k = =1) - return '0'; - Else if(k = =2) - return 'X'; + Else - return '0'+ A-K; + } A intMain () at { - stringNumber ; - while(CIN >> number) && number! ="-1") - { - if(number[ -] ==s (number)) -cout <<"1"<<Endl; in Else -cout <<"0"<<Endl; to } +System"Pause"); - return 0; the}
Identity Check (c + + implementation)