pat-B-1031. Identification of identification Card (15)

Source: Internet
Author: User

1031. Identification of identity card (15) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue

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 10
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

1#include <stdio.h>2#include <string.h>3 intMainvoid)4 {5     intn,i,j,z,k=0, D;6     intb[ -]={7,9,Ten,5,8,4,2,1,6,3,7,9,Ten,5,8,4,2};7     Chara[ -];8     Charc[ One]={'1','0','X','9','8','7','6','5','4','3','2'};9scanf"%d",&n);Ten      for(i=0; i<n;i++) One     { AD=0; -z=0; -scanf"%s", a); the          for(j=0;j< -; j + +) -         { -             if('0'<=a[j]&&a[j]<='9') -             { +z+= ((a[j]-'0') *b[j])% One; -             } +             Else AD=1; at         } -z%= One; -         if(c[z]==a[ -]&&d!=1) -         { -k++; -         } in         Else -         { toprintf"%s\n", a); +         } -     } the     if(k==N) *     { $printf"All passed\n");Panax Notoginseng     } -     return 0; the}

pat-B-1031. Identification of identification Card (15)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.