1031. 查验身份证(15)

#include
using namespace std;

int main()
{
    int weight[17] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    bool flag[100] = {false};
    int N;
    cin >> N;
    fflush(stdin);
    char id[100][20];
    int m = 0;
    int ct = 0;
    while (mint check = 0;
        gets(id[m]);
        for (int i = 0; i < 18; i++){ 
            if (i != 17){
                check+=weight[i] * (id[m][i]-48);
            }
            else{
                check %= 11;
            }
        }
        int M=-1;
        char MM;
        if (check >= 3){
            M = 12 - check;
        }
        else if (check>=0&&check < 2){
            M = 1 - check;
        }
        else{
            MM = 'X';
        }
        if (M != -1){
            if (M == id[m][17]-48){
                ct++;
                flag[m] = true;
            }
            else{
                //cout << id;
            }
        }
        else{
            if (id[m][17] == 'X'){
                ct++;
                flag[m] = true;
            }
            else{
                //cout << id;
            }
        }
        m++;
    }
    if (ct == N){
        cout << "All passed";
    }
    else{
        for (int i = 0; i < N; i++){
            if (!flag[i]){
                cout << id[i]<return 0;
}

用题目给的测试两个测试用例测试,结果显示和答案给的一样,但是不知道为什么一直无法通过……希望有小伙伴发现我的错误告诉我一下,非常感谢!

你可能感兴趣的:(PAT(Basic,Level),Practise)