输入样例1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
输出样例1:
12010X198901011234
110108196711301866
37070419881216001X
输入样例2:
2
320124198808240056
110108196711301862
输出样例2:
All passed
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] a= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char[] M = {'1','0','X','9','8','7','6','5','4','3','2'};
boolean flag=true;
Scanner scanner = new Scanner(System.in);
int n=scanner.nextInt();
String[] idcard = new String[n];
for(int i=0;i<n;i++) {
idcard[i]=scanner.next();
}
for(int i=0;i<n;i++) {
int sum=0;
for(int j=0;j<17;j++) {
sum=sum+(idcard[i].charAt(j)-'0')*a[j];
//数字乘以权重
}
int Z=sum%11;
if(M[Z]!=idcard[i].charAt(17)) {
flag=false;
System.out.println(idcard[i]);
}
}
if(flag) {
System.out.println("All passed");
}
}
}