L1-016 查验身份证

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <cctype>

using namespace std;
#define maxn 3000

int main()
{
    string ids[maxn] ;
    int N,count=0;
    cin >>N;
    int weight[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
    char check[11] = { '1', '0', 'X', '9', '8', '7', '6', '5','4','3', '2'};
    for (int i = 0; i < N; i++)
        cin >>ids[i];
    for(int i = 0;i < N;i++)
    {
        int sum = 0,flag =1;
        for (int j = 0; j < 17; j++)
        {
            if(!isdigit(ids[i][j])){ cout <<ids[i]<<endl; flag = 0; break; } 
            else sum += (ids[i][j]-48)*weight[j] ;

        }
        if(!flag) continue;
        if(ids[i][17] != check[sum%11])cout <<ids[i]<<endl;
        else  count ++;
    }
    if(count == N)
        cout << "All passed";
    return 0;
}

 

posted on 2019-10-22 12:35  TigerDZ  阅读(142)  评论(0编辑  收藏  举报

导航