#include<iostream>#include<string>#include<cmath>
using namespace std;
int main(){
int pj[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, 4 , 2 };
int z[11]={ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 };
char m[11]={'1','0','X','9','8','7','6','5','4','3','2'};
int n,i,j,k,l;
int t,x,y;
int s[100]={0};
cin>>n;
char a[102][18];
int f[1000]={0};
int q[1000]={0};
getchar();
for(i=0;i<n;i++){
scanf("%s",a[i]);}
for(i=0;i<n;i++){
for(j=0;j<17;j++){
if(!(a[i][j]>=48&&a[i][j]<=9+48)){
f[i]++;break;}
s[i]=s[i]+((int)(a[i][j]-'0'))*pj[j];}
q[i]=s[i]%11;
if(a[i][17]!=m[q[i]]){
f[i]++;}}
int e=0;
for(i=0;i<n;i++){
if(f[i]!=0){
e++;
for(j=0;j<18;j++)
printf("%c",a[i][j]);
printf("\n");}}
if(e==0)
printf("All passed");return 0;}
标准答案
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cin>>n;
string* str =newstring[n];for(int i =0;i<n;i++){
cin>>str[i];}
char a[n];
int sum[n];
int shaobing[n];for(int i =0;i<n;i++){
a[i]=str[i].at(17);
sum[i]=0;
shaobing[i]=1;}
char M[11]={'1','0','X','9','8','7','6','5','4','3','2'};
int N[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};for(int j =0;j<n;j++){for(int i=0;i<17;i++){if(str[j].at(i)>='0'&&str[j].at(i)<='9'){
sum[j]+=(str[j].at(i)-'0')*N[i];}else{
shaobing[j]=0;break;}}}
int flag =1;for(int i=0;i<n;i++){if(shaobing[i]==0||M[sum[i]%11]!=a[i]){
cout<<str[i]<<endl;
flag =0;}}if(flag ==1){
cout<<"All passed"<<endl;}return0;}