L1-016 查验身份证 (15分)|C++实现

L1-016 查验身份证 (15分)

在这里插入图片描述

输入样例1:

4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X

输出样例1:

12010X198901011234
110108196711301866
37070419881216001X

输入样例2:

2
320124198808240056
110108196711301862

输出样例2:

All passed

C++代码如下:

**
#include<iostream>
using namespace std;
char q[12] = {'1','0','X','9','8','7','6','5','4','3','2'}; 
int w[20] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int main()
{
	int N,ans=0;
	cin >> N;
	while(N--)
	{
		char a[20]; 
		int sum = 0;
		cin >> a;
		for(int i = 0;i < 17;i++)	sum +=  (a[i] - '0')*w[i]; 
		if(a[17] != q[sum % 11])
		{
			cout << a << endl;	
			ans ++;
		}
	}
	if(ans == 0)
		cout << "All passed" << endl;	
	return 0;
}
**
原创文章 50 获赞 139 访问量 2万+

猜你喜欢

转载自blog.csdn.net/diviner_s/article/details/105219195