当前位置:网站首页>B1031 查验身份证
B1031 查验身份证
2022-07-27 05:01:00 【叶辰 .】
1031 查验身份证 (15 分)
一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:
首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:
Z:0 1 2 3 4 5 6 7 8 9 10
M:1 0 X 9 8 7 6 5 4 3 2
现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。
输入格式:
输入第一行给出正整数N(≤100)是输入的身份证号码的个数。随后N行,每行给出1个18位身份证号码。
输出格式:
按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出All passed。
输入样例
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
输出样例
12010X198901011234
110108196711301866
37070419881216001X
输入样例
2
320124198808240056
110108196711301862
输出样例
All passed
题目分析:
- 注意 检查前17位是否全为数字
- 计算1位校验码是否正确。
代码如下:
#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;
}
边栏推荐
- Three paradigms, constraints, some keyword differences,
- 树莓派输出PWM波驱动舵机
- Mysql表的约束
- DBUtils
- How do I reset Photoshop preferences? PS method of resetting preferences
- Read write separation and master-slave synchronization
- C中文件I/O的使用
- C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)
- Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
- 事件的接受与忽略
猜你喜欢

JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存

探寻通用奥特能平台安全、智能、性能的奥秘!

How to sinicize the JMeter interface?

支付流程如何测试?

JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位

File dialog box

Introduction to MySQL optimization

Introduction to Kali system ARP (network disconnection sniffing password packet capturing)

How do I reset Photoshop preferences? PS method of resetting preferences

How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
随机推荐
Row, table, page, share, exclusive, pessimistic, optimistic, deadlock
Li Kou achieved the second largest result
【牛客讨论区】第七章:构建安全高效的企业服务
Svn usage details
2、 MySQL advanced
集成开发环境Pycharm的安装及模板设置
How to copy Photoshop layers to other documents
Event
Could not autowire. No beans of ‘userMapper‘ type found.
Basic operation of vim
测试基础5
传智教育|软件测试工程师未来的发展方向有哪些?
JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位
Could not autowire.No beans of ‘userMapper‘ type found.
Knapsack problem DP
JVM上篇:内存与垃圾回收篇八--运行时数据区-方法区
File processing (IO)
Invert a Binary Tree
文件处理(IO)
老子云携手福昕鲲鹏,首次实现3D OFD三维版式文档的重大突破