PAT 乙级1031 查验身份证 测试点2无法通过 没有X大小写的问题
#include <bits/stdc++.h>
using namespace std;
char sentence[25];
int weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char M[11]={'1','0','X','9','8','7','6','5','4','3','2'};
int main(){
int n,flag=1;
scanf("%d",&n);
getchar();
while(n--){
int sum=0;
scanf("%s",sentence);
if(n!=0) getchar();
for(int i=0;i<=16;i++){
if(sentence[i]>='0'&&sentence[i]<='9'){
sum+=(sentence[i]-'0')*weight[i];
}else{
flag=0;
printf("%s\n",sentence);
break;
}
}
int z=sum%11;
char m=M[z];
if(sentence[17]!=m){
flag=0;
printf("%s\n",sentence);
}
}
if(flag==1)
printf("All passed");
return 0;
}