A valid ID number consists of 17 regions, date number and sequence number plus 1-bit check code. The calculation rules for the checksum code are as follows:
The first 17 digits are weighted to sum, the weights are assigned: {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}, then the calculated and 11 modulo values are obtained z, and the values of Z-values and checksum m are corresponding to the following relationship:
Z:0 1 2 3 4 5 6 7 8 9 m:1 0 X 9 8 7 6 5 4 3 2
Now given some ID number, please verify the validity of the verification code, and output the number of the problem.
Input format:
Enter the first line to give a positive integer n (<= 100) is the number of input ID number. Then n rows, each row gives 1 18-digit ID numbers.
Output format:
Output 1 Problematic ID numbers per line in the order in which they were entered. This does not test whether the first 17 bits are reasonable, only check whether the first 17 digits are all digital and the last 1-bit check code is calculated accurately. If all numbers are normal, output "all passed".
Input Sample 1:
432012419880824005612010x19890101123411010819671130186637070419881216001x
Output Example 1:
12010x19890101123411010819671130186637070419881216001x
Input Sample 2:
2320124198808240056110108196711301862
Output Example 2:
All passed
Thinking: Mastering the relationship between global variables and local variables
1#include <stdio.h>2 //take the modulus to find the remainder3 4 intweight[ -]={5 7,9,Ten,5,8,4,2,1,6,3,7,9,Ten,5,8,4,26 };7 Charstandard[ One]={8 '1','0','X','9','8','7','6','5','4','3','2' 9 };Ten intMainintargcChar*argv[]) One { A Charstr[ -]; - BOOLAll=true; - intcount; thescanf"%d",&count); - GetChar (); - while(count--) - { + BOOLflag=true; -scanf"%s", str); + intsum=0; A for(intI=0;i< -; i++) at { - if(str[i]>='0'&&str[i]<='9') -sum=sum+ (str[i]- -)*Weight[i]; - Else - { -flag=false; in Break; - } to } +sum=sum% One; - if(str[ -]=='x') thestr[ -]-= +; * if(standard[sum]!=str[ -]) $ {Panax Notoginseng //determine case x -flag=false; the } + if(!flag) A { theprintf"%s\n", str); +All=false; - } $ $ } - if(All) -printf"All passed\n"); the return 0; -}
View Code
PAT1031. Identification of identification Card (15)