PAT乙题 1031. 查验身份证(15)

2018/01/26 PAT 共 763 字,约 3 分钟
//cpp:
#include <iostream>
#include <algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<ctype.h>
#include<set>
using namespace std;
int main() {
#ifdef LOCAL
	freopen("D:\\datain.txt", "r", stdin);
#endif
	int n;
	string a;
	cin >> n;
	char m[12] = { '1','0','X','9','8','7','6','5','4','3','2' };
	int b[17] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
	bool flag = true;
	for (int i = 0; i < n; i++) {
		cin >> a;
		int sum = 0;
		for (int j = 0; j < 17; j++) {
			sum += (a[j] - '0')*b[j];
			//cout << "+" << a[j] - '0';
		}
		//cout <<"sum"<< sum << endl;
		sum = sum % 11;
		//cout << sum << endl;
		//cout << m[sum] << endl;
		if (m[sum] != a[17]) {
			cout << a << endl;
			flag = false;
		}
	}
	if (flag)
		cout << "All passed";
}

Search

    Table of Contents