#include<iostream>
using namespace std;
int W[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
char M[17] = { '1', '0' ,'X', '9', '8', '7', '6', '5', '4', '3', '2' };
void otos(string id)
{
cout << id << endl;
}
void test()
{
int num;
//循环次数
cin >> num;
int count = 0;
for (int i = 0; i < num; i++)
{
int sum = 0;
string id;
cin >> id;
for (int j = 0; j < 17; j++)
{
int nid = 0;
nid = (int)id[j] - 48;
sum = W[j] * nid + sum;
}
char res = ' ';
res = M[sum%11];
//cout << res << endl;
if (res != id[17])
{
otos(id);
//count作为错误计数
count = count + 1;
}
}
//if count==0 就是没有错误的
if (count == 0)
{
cout << "All passed" << endl;
}
}
int main()
{
test();
return 0;
}
【PAT-B1031】 查验身份证 (15 分)(c++)
最新推荐文章于 2023-12-25 23:30:45 发布