# PAT Basic 1031

##### 1031 查验身份证(15)（15 分）

Z：0 1 2 3 4 5 6 7 8 9 10\ M：1 0 X 9 8 7 6 5 4 3 2

``````4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X``````

``````12010X198901011234
110108196711301866
37070419881216001X``````

``````2
320124198808240056
110108196711301862``````

``All passed　　题解：这道题没有什么难度，毕竟只有15分，老老实实按照题意模拟就好。代码如下：``
``` 1 #include<iostream>
2
3 using namespace std;
4
5 int main()
6 {
7     string a;
8     int n, c = 0, ac = 1;
9     int b[17] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
10     char d[11] = {‘1‘,‘0‘, ‘X‘, ‘9‘, ‘8‘, ‘7‘, ‘6‘, ‘5‘, ‘4‘, ‘3‘, ‘2‘};
11     cin>>n;
12     while( n--){
13         c = 0;
14         cin>>a;
15         for( int i = 0; i < 17 ; i++){
16             c += (a[i] - ‘0‘)*(b[i]);
17         }
18         c = c%11;
19         if(a[17] != d[c]){
20             ac = 0;
21             cout<<a<<endl;
22         }
23     }
24     if(ac) cout<<"All passed";
25     return 0;
26 }```

`` ``

PAT Basic 1031

(0)
(0)

0条