Click
Here to go back to the homepage.
FBI Universal Control Numbers Solution:
import java.util.HashMap;
import java.util.Scanner;
public class Kattis {
static char arr[] = new char[]{'0','1','2','3','4','5','6','7','8','9','A','C','D','E','F','H','J','K','L','M','N','P','R','T','V','W','X'};
static HashMap<Character, Character> hm = new HashMap<Character, Character>();
static HashMap<Character, Character> hm2 = new HashMap<Character, Character>();
public static void main(String[] args){
hm.put('B', '8');
hm.put('G', 'C');
hm.put('I', '1');
hm.put('O', '0');
hm.put('Q', '0');
hm.put('S', '5');
hm.put('U', 'V');
hm.put('Y', 'V');
hm.put('Z', '2');
hm2.put('C', 'B');
hm2.put('D', 'C');
hm2.put('E', 'D');
hm2.put('F', 'E');
hm2.put('H', 'F');
hm2.put('J', 'G');
hm2.put('K', 'H');
hm2.put('L', 'I');
hm2.put('M', 'J');
hm2.put('N', 'K');
hm2.put('P', 'L');
hm2.put('R', 'M');
hm2.put('T', 'N');
hm2.put('V', 'O');
hm2.put('W', 'P');
hm2.put('X', 'Q');
Scanner sc = new Scanner(System.in);
int a = Integer.parseInt(sc.nextLine());
int[] p = new int[9];
for(int i = 0; i < a; i++){
StringBuilder sb = new StringBuilder();
System.out.print(i+1 + " ");
int j = 0;
char line[] = sc.nextLine().split(" ")[1].toCharArray();
for (int u = 0; u < line.length; u++){
if (hm.containsKey(line[u])){
line[u] = hm.get(line[u]);
}
}
for (int u = 0; u < line.length; u++){
if(hm2.containsKey(line[u])){
line[u] = hm2.get(line[u]);
}
}
for(char c:line){
p[j++] = Integer.parseInt(""+c, 27);
}
if((2 * p[0] + 4 * p[1] + 5 * p[2] + 7 * p[3] + 8 * p[4] + 10 * p[5] + 11 * p[6] + 13 * p[7]) % 27 == p[8]){
for(int q = 0; q < line.length-1; q++){
sb.append(line[q]);
}
System.out.println(Long.parseLong(sb.toString(), 27));
}
else {
System.out.println("Invalid");
}
}
}
}