天梯赛训练1 7-8 查验身份证

水题 按照题目意思来就行了

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,b[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    char a[11]={'1','0','X','9','8','7','6','5','4','3','2'};
    string number;
    cin>>n;int sum=0;
    int m=n;
    while(n--)
    {
        int flag=0,zhi=0;
        cin>>number;
        int len=number.size();
        for(int i=0;i<=16;i++)
        {
            if(number[i]<'0'||number[i]>'9')  //不符合
            {
                cout << number << endl;
                flag=1;
                break;
            }
        }
        if(!flag)
        {
            for(int i=0;i<=16;i++)
            {
                int p;
                stringstream convert;
                convert << number[i];  //先输出
                convert >> p;     //在输入
                zhi=zhi+p*b[i];
            }
                int shuzi=zhi%11;
                if(a[shuzi]==number[17])
                    sum++;
                else
                    cout << number << endl;

         }
    }
    if(sum==m)
        cout << "All passed" << endl;
    return 0;
}

posted @ 2019-03-06 13:48  厂长在线养猪  Views(263)  Comments(0Edit  收藏  举报