1031 check ID (15 points)
A valid area 17 by the ID number, order number, and date code plus a checksum component. Checksum calculation rule is as follows:
First, a weighted summation of the first 17 digits, weight distribution is: {} 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2; then the obtained value and the calculated modulo 11 Z
; according to the relation corresponding to the final Z
value and checksum M
value:
Z:0 1 2 3 4 5 6 7 8 9 10 M:1 0 X 9 8 7 6 5 4 3 2
Now given some of the ID number, please verify the validity check code, and outputs the number in question.
Input formats:
Input of the first row is given a positive integer N ( ≤) is the number of the input ID number. Then N rows, each row 18 is given an ID number.
Output formats:
Each output line has a problem in the order of the input ID number. Here is not whether a reasonable inspection before 17, just before checking whether all numbers 17 and finally a checksum is calculated accurately. If all the numbers are normal, the output All passed
.
Sample Input 1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
Output Sample 1:
12010X198901011234
110108196711301866
37070419881216001X
Sample Input 2:
2
320124198808240056
110108196711301862
Output Sample 2:
All passed
首次通过代码:
. 1 #include <stdio.h> 2 . 3 int main () { . 4 int NUM; // ID number entered . 5 char ID [ 20 is ]; // ID value character . 6 int SUM = 0 ; // weighting and 7 int Z; // weighted and die . 8 int ERROR_ID = 0 ; // number of errors recorded ID . 9 int in Flag = 0 ; // front ID bit is the letter. 17 10 int weight [] = { . 7 , . 9 ,10 , 5 , 8 , 4 , 2 , 1 , 6 , 3 , 7 , 9 , 10 , 5 , 8 , 4 , 2 }; // weights . 11 int the reflect [] = { 1 , 0 , 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 }; // mapping relationship 12 scanf("%d",&num); 13 for(int i=0;i<num;i++){ 14 scanf("%s",id);//输入ID 15 for(int j=0;j<17;j++){ 16 if(id[j]>='0'&&id[j]<='9') 17 sum+=(id[j]-'0')*weight[j];calculate the weighted and// 18 is the else { . 19 In Flag = . 1 ; BREAK ; 20 is } 21 is } 22 is 23 is Z = SUM% . 11 ; // a weighted sum modulo 24 IF (Z == 2 && ID [ . 17 ] == ' X- ' &&! In Flag); 25 the else IF (the reflect [Z] == (ID [ . 17 ] - ' 0 ' ) && In Flag!); // this bit card, forget forget subtracting ID for the character '0' 26 is the else { 27 IF(ERROR_ID> 0 ) the printf ( " \ n- " ); // if the number of error ID is not 0 first wrap and then output 28 ERROR_ID ++ ; 29 the printf ( " % S " , ID); 30 } 31 is In Flag = 0 ; SUM = 0 ; 32 } 33 is IF ( 0 == ERROR_ID) the printf ( " All passed " ); 34 is return 0 ; 35 }