PAT乙级1031
https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 #include<cmath> 6 #include<vector> 7 #include<queue> 8 #include<bits/stdc++.h> 9 using namespace std; 10 int n; 11 bool flag; 12 int a[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; 13 char r[11]={'1','0','X','9','8','7','6','5','4','3','2'}; 14 vector<string> b; 15 int main() 16 { 17 cin>>n; 18 int tot=0; 19 string m; 20 for(int i=0;i<n;i++) 21 { 22 flag=0; 23 int ans=0; 24 cin>>m; 25 for(int j=0;j<17;j++) 26 { 27 if(m[j]<'0'||m[j]>'9') 28 { 29 flag=1;break; 30 } 31 ans+=a[j]*(m[j]-'0'); 32 } 33 int t=ans%11; 34 if(r[t]!=m[17]) 35 flag=1; 36 if(flag==1) 37 {b.push_back(m);tot++;} 38 } 39 if(tot){ 40 for(vector<string>::iterator i=b.begin();i!=b.end();i++) 41 cout<<*i<<endl; 42 } 43 else 44 cout<<"All passed"; 45 return 0; 46 }