当前位置:网站首页>B1031 check ID card
B1031 check ID card
2022-07-27 05:20:00 【Ye Chen】
1031 Check your ID card (15 branch )
A legal ID number is from 17 Location 、 Date number and sequence number plus 1 Bit check code composition . Check code calculation rules are as follows :
First of all, to the front 17 Bit number weighted sum , The weight is assigned to :{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; Then the sum of the calculated values is compared to the 11 Take the modulus to get the value Z; Finally, according to the following relationship Z Value and check code 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 give me some ID number. , Please verify the validity of the check code , And output the problem number .
Input format :
Enter the first line to give a positive integer N(≤100) The number of the ID number entered. . And then N That's ok , Each line gives 1 individual 18 I. D. number .
Output format :
Output each line in the order of input 1 Question Id number . This is not before the test 17 Is it reasonable , Just before checking 17 Are all digits and last 1 Accurate calculation of bit check code . If all the numbers are OK , The output All passed.
sample input
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
sample output
12010X198901011234
110108196711301866
37070419881216001X
sample input
2
320124198808240056
110108196711301862
sample output
All passed
Topic analysis :
- Be careful Before inspection 17 Whether all bits are numbers
- Calculation 1 Check whether the bit check code is correct .
The code is as follows :
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
char m[]={'1','0','X','9','8','7','6','5','4','3','2'};
int z[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
cin>>n;
char s[101][19];
int sum[101]={0},flag[101]={0},g=0;
for(int i=0;i<n;i++){
scanf("%s",s[i]);
s[i][18]='\0';
for(int j=0;j<17;j++){
if(s[i][j]<='9'&&s[i][j]>='0'){
sum[i]+=(s[i][j]-'0')*z[j];
}else{
flag[i]=1;
break;
}
}
if(flag[i]==0){
int a=sum[i]%11;
if(m[a]-s[i][17]!=0){
flag[i]=1;
}
}
if(flag[i]==1){
g++;
}
}
if(g==0){
cout<<"All passed";
}else{
for(int i=0;i<n;i++){
if(flag[i]==1){
printf("%s\n",s[i]);
}
}
}
return 0;
}
边栏推荐
猜你喜欢

Installation and template setting of integrated development environment pychar

《Robust and Precise Vehicle Localization based on Multi-sensor Fusionin Diverse City Scenes》翻译

支付流程如何测试?

What should test / development programmers over 35 do? Many objective factors

JVM上篇:内存与垃圾回收篇十一--执行引擎

Detailed description of binary search tree

Shell course summary

二、MySQL高级

B1021 single digit statistics

Database connection pool & Druid usage
随机推荐
数据库连接池&&Druid使用
Use of collection framework
Advantages of smart exhibition hall design and applicable industry analysis
JVM上篇:内存与垃圾回收篇二--类加载子系统
35. Scroll
MQ message queue is used to design the high concurrency of the order placing process, the generation scenarios and solutions of message squeeze, message loss and message repetition
JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
Dialog data transfer
JVM Part 1: memory and garbage collection part 12 -- stringtable
Explore the mysteries of the security, intelligence and performance of the universal altek platform!
《Robust and Precise Vehicle Localization based on Multi-sensor Fusionin Diverse City Scenes》翻译
Introduction to Kali system ARP (network disconnection sniffing password packet capturing)
Deep Qt5 signal slot new syntax
B1022 D进制的A+B
Installation and template setting of integrated development environment pychar
枚举类实现单例模式
Detailed explanation of pointer constant and constant pointer
35.滚动 scroll
Raspberry pie output PWM wave to drive the steering gear
JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area