输入样例1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
输出样例1:
12010X198901011234
110108196711301866
37070419881216001X
标题输入样例2:
2
320124198808240056
110108196711301862
输出样例2:
All passed
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
public static int[] weight = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
public static int[] Z = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
public static String[] M = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
public static boolean isValid(String id) {
int w = 0;
for (int i = 0; i < 17; i++) {
if((id.charAt(i)-'0') >=0 && (id.charAt(i)-'0')<=9){
w = w + (id.charAt(i) - '0') * weight[i];
}
else
return false;
}
int z = w % 11;
if (M[Z[z]].compareToIgnoreCase(id.charAt(17) + "") == 0) return true;
return false;
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
boolean flag = true;
for (int i = 0; i < n; i++) {
String id = br.readLine();
if (isValid(id)) {
} else {
flag = false;
System.out.println(id);
}
}
if (flag) System.out.println("All passed");
}
}