pat_b_1031 查验身份证


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


          分析: 简单题


          代码:

                  

//pat b 1031
#include 
#include 
#include 
#include 
#include 
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>s;
            if(!judge()){
                cout<

你可能感兴趣的:(pat_b)