1031 查验身份证
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int r[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
bool ifconfirm(string s, map<int, char> confirm)
{
int z = 0;
for (int j = 0; j < 17; j++)
{
if (s[j] >= '0' && s[j] <= '9')
{
z += r[j] * (s[j]-'0');
}
else
{
return false;
}
}
z = z % 11;
if (confirm[z]==s[17])
{
return true;
}
else
{
return false;
}
}
int main()
{
int n;
cin >> n;
vector<string>s(n);
vector<string> problem;
map<int, char> confirm;
confirm[0] = '1';
confirm[1] = '0';
confirm[2] = 'X';
confirm[3] = '9';
confirm[4] = '8';
confirm[5] = '7';
confirm[6] = '6';
confirm[7] = '5';
confirm[8] = '4';
confirm[9] = '3';
confirm[10] = '2';
for (int i = 0; i < n; i++)
{
cin >> s[i];
bool c = ifconfirm(s[i], confirm);
if (c==false)
{
problem.push_back(s[i]);
}
}
if (problem.size() == 0)
cout << "All passed";
else
{
for (int i = 0; i < problem.size(); i++)
{
cout << problem[i] << endl;
}
}
return 0;
}