pat_b_1031 查验身份证

来源:互联网 发布:淘宝退货地址 编辑:程序博客网 时间:2024/05/02 00:25


           http://www.patest.cn/contests/pat-b-practise/1031


          分析: 简单题


          代码:

                  

<span style="font-size:18px;">//pat b 1031#include <iostream>#include <stdio.h>#include <string>#include <cstring>#include <ctype.h>using namespace std;const int maxn = 101;const char M[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};const int  W[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};int n;string s;bool judge(){    for(int i=0; i< 17; i++){        if(!isdigit(s[i])) return false;    }    int sum=0;    for(int i=0; i<17; i++){        sum += (s[i]-'0')*W[i];    }    char c =M[ sum % 11 ];    return c==s[17] ? true : false;}int main(){    freopen("in.txt","r",stdin);    bool flag;    while(cin>>n){        flag=false;        for(int i=0; i<n; i++){            cin>>s;            if(!judge()){                cout<<s<<endl;                flag=true;            }        }        if(!flag) cout<<"All passed"<<endl;    }    return 0;}</span>

0 0