当前位置:网站首页>Pat class B 1031 checking ID card (15 points)
Pat class B 1031 checking ID card (15 points)
2022-06-21 07:22:00 【myriadddddd】
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 1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
sample output 1:
12010X198901011234
110108196711301866
37070419881216001X
sample input 2:
2
320124198808240056
110108196711301862
sample output 2:
All passed
analysis :
First, accumulate the first 17 digits of the ID card , If the position is not a number, it means that this string is not an ID card ; Right. 18 Bit special judgment , If it is X Just use 10 Instead of , If not, add up the value . The final sum and remainder 11 And M Verify whether the check code in can correspond to the upper .
Code :
#include <iostream>
using namespace std;
// The weight
int weight[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
// Check code
int M[] = { 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 };
bool isTrue(string str) {
int sum = 0;
for (int i = 0; i != 17; i++) {
if (str[i] < '0' || str[i] > '9') // 0 ~ 17 Bits are all numbers
return false;
sum += (str[i] - '0') * weight[i]; // Calculate weight
}
// Judge whether the 18th digit is a letter
int temp = (str[17] == 'X') ? 10 : (str[17] - '0');
return M[sum % 11] == temp; // Compare with the check code
}
int main() {
int N;
string str;
bool flag = false;
cin >> N;
for (int i = 0; i != N; i++) {
cin >> str;
if (!isTrue(str)) {
cout << str << endl;
flag = true;
}
}
if (flag == 0)
cout << "All passed" << endl;
return 0;
}
边栏推荐
- [transfer] liurun: don't discuss business with people without logic
- Enterprise level development and use POI stepping on pit inventory
- How to use MES management system to realize error prevention and early warning
- Japanese programming learning website
- 缺失数据填补数据集介绍(1)——多种数据集介绍及数据集预处理(breast、covertype、credit、eeg、iris和letter)
- Postman publishing API documentation
- How to deal with the error message of concurrentmodificationexception?
- QML控件类型:Drawer
- Yield Guild Games 与 Discord 上的第一款 MMORPG ——Tatsumeeko 达成合作
- Transport layer TCP header - serial number and acknowledgement number
猜你喜欢

Unittest use

EasyExcel-简介-01

Google Earth Engine(GEE)——全球农田有机土壤碳和氮排放(1992-2018年度)数据集

什么是Eureka?Eureka能干什么?Eureka怎么用?

Root cause analysis | inventory of nine scenarios with abnormal status of kubernetes pod

海思系列量产硬件调试记录

Yield Guild Games 与 Walken 达成合作

微信小程序_5,全局配置

Do you know all the extension racks of ThinkPHP?

Understand this point
随机推荐
app安全滲透測試詳細方法流程
Weather forecast applet source code / weather wechat applet source code
数据分析之:不同行业的常见指标
C language program design - Sanzi chess (semester homework)
[FPGA wavelet transform] Verilog implementation of image 9/7 integer wavelet transform based on FPGA
Use js to switch between clickable and non clickable page buttons
Easyexcel exclude display field-02
Vite + whistle: a development environment proxy solution once and for all
集线器、交换机、路由器
缺失数据填补数据集介绍(1)——多种数据集介绍及数据集预处理(breast、covertype、credit、eeg、iris和letter)
Analyse des données: indicateurs communs pour différentes industries
Kubernetes cluster setup detailed tutorial
js操作Cookie,js设置Cookie值,js读取Cookie值
Four necessary steps for building a digital factory
Can customer managers be relied on online? Is the fund safe
Wechat applet_ 6. Network data request
Introduction to missing data filling dataset (2) -- Introduction to multiple datasets and dataset preprocessing (mushroom, news, spam, wine red and year)
Random random number class
源代码加密产品的分析
Do you know all the extension racks of ThinkPHP?