Click
Here to go back to the homepage.
False Sense of Security Solution:
import java.util.*;
public class Kattis {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String originalLine;
HashMap<Character, String> hm = new HashMap<>();
hm.put('A', "12");
hm.put('B', "2111");
hm.put('C', "2121");
hm.put('D', "211");
hm.put('E', "1");
hm.put('F', "1121");
hm.put('G', "221");
hm.put('H', "1111");
hm.put('I', "11");
hm.put('J', "1222");
hm.put('K', "212");
hm.put('L', "1211");
hm.put('M', "22");
hm.put('N', "21");
hm.put('O', "222");
hm.put('P', "1221");
hm.put('Q', "2212");
hm.put('R', "121");
hm.put('S', "111");
hm.put('T', "2");
hm.put('U', "112");
hm.put('V', "1112");
hm.put('W', "122");
hm.put('X', "2112");
hm.put('Y', "2122");
hm.put('Z', "2211");
hm.put('_', "1122");
hm.put('.', "2221");
hm.put(',', "1212");
hm.put('?', "2222");
HashMap<String, Character> reverse_hm = new HashMap<>();
reverse_hm.put("12" ,'A');
reverse_hm.put("2111",'B');
reverse_hm.put("2121",'C');
reverse_hm.put("211" ,'D');
reverse_hm.put("1" ,'E');
reverse_hm.put("1121",'F');
reverse_hm.put("221" ,'G');
reverse_hm.put("1111",'H');
reverse_hm.put("11" ,'I');
reverse_hm.put("1222",'J');
reverse_hm.put("212" ,'K');
reverse_hm.put("1211",'L');
reverse_hm.put("22" ,'M');
reverse_hm.put("21" ,'N');
reverse_hm.put("222" ,'O');
reverse_hm.put("1221",'P');
reverse_hm.put("2212",'Q');
reverse_hm.put("121" ,'R');
reverse_hm.put("111" ,'S');
reverse_hm.put("2" ,'T');
reverse_hm.put("112" ,'U');
reverse_hm.put("1112",'V');
reverse_hm.put("122" ,'W');
reverse_hm.put("2112",'X');
reverse_hm.put("2122",'Y');
reverse_hm.put("2211",'Z');
reverse_hm.put("1122",'_');
reverse_hm.put("2221",'.');
reverse_hm.put("1212",',');
reverse_hm.put("2222",'?');
while (sc.hasNextLine()) {
originalLine = sc.nextLine();
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
StringBuilder result = new StringBuilder();
for (int i = 0; i < originalLine.length(); i++) {
sb.append(hm.get(originalLine.charAt(i)));
sb2.append(hm.get(originalLine.charAt(i)).length());
}
String numbers = sb2.reverse().toString();
int numcount = 0;
for (int i = 0; i < originalLine.length(); i++) {
result.append(reverse_hm.get(sb.substring(numcount, numcount + Character.digit(numbers.charAt(i), 10))));
numcount += Character.digit(numbers.charAt(i), 10);
}
System.out.println(result);
}
}
}