Main.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class Main {
static HashMap
<String,String
> MORSE
= new HashMap
<String,String
>(); static HashMap
<String,String
> REVERSE_MORSE
= new HashMap
<String,String
>();
applyMap();
while ((str = reader.readLine()) != null) {
int[] codes = new int[str.length()];
for (int i = 0; i < str.length(); i++) {
String tmp
= MORSE.
get(str.
charAt(i
)+""); codes[i] = tmp.length();
out = out + tmp;
}
for (int i = 0; i < codes.length/2; i++) {
int tmp = codes[i];
codes[i] = codes[codes.length-i-1];
codes[codes.length-i-1] = tmp;
}
int total = 0;
for (int i = 0; i < codes.length; i++) {
int tmp_i = codes[i];
String tmp_s
= out.
substring(total, total
+tmp_i
); total += tmp_i;
System.
out.
print(REVERSE_MORSE.
get(tmp_s
)); }
}
}
static void applyMap() {
MORSE.put("A", ".-");
MORSE.put("B", "-...");
MORSE.put("C", "-.-.");
MORSE.put("D", "-..");
MORSE.put("E", ".");
MORSE.put("F", "..-.");
MORSE.put("G", "--.");
MORSE.put("H", "....");
MORSE.put("I", "..");
MORSE.put("J", ".---");
MORSE.put("K", "-.-");
MORSE.put("L", ".-..");
MORSE.put("M", "--");
MORSE.put("N", "-.");
MORSE.put("O", "---");
MORSE.put("P", ".--.");
MORSE.put("Q", "--.-");
MORSE.put("R", ".-.");
MORSE.put("S", "...");
MORSE.put("T", "-");
MORSE.put("U", "..-");
MORSE.put("V", "...-");
MORSE.put("W", ".--");
MORSE.put("X", "-..-");
MORSE.put("Y", "-.--");
MORSE.put("Z", "--..");
MORSE.put("_", "..--");
MORSE.put(",", ".-.-");
MORSE.put(".", "---.");
MORSE.put("?", "----");
REVERSE_MORSE.put(".-", "A");
REVERSE_MORSE.put("-...", "B");
REVERSE_MORSE.put("-.-.", "C");
REVERSE_MORSE.put("-..", "D");
REVERSE_MORSE.put(".", "E");
REVERSE_MORSE.put("..-.", "F");
REVERSE_MORSE.put("--.", "G");
REVERSE_MORSE.put("....", "H");
REVERSE_MORSE.put("..", "I");
REVERSE_MORSE.put(".---", "J");
REVERSE_MORSE.put("-.-", "K");
REVERSE_MORSE.put(".-..", "L");
REVERSE_MORSE.put("--", "M");
REVERSE_MORSE.put("-.", "N");
REVERSE_MORSE.put("---", "O");
REVERSE_MORSE.put(".--.", "P");
REVERSE_MORSE.put("--.-", "Q");
REVERSE_MORSE.put(".-.", "R");
REVERSE_MORSE.put("...","S");
REVERSE_MORSE.put("-","T");
REVERSE_MORSE.put("..-","U");
REVERSE_MORSE.put("...-","V");
REVERSE_MORSE.put(".--","W");
REVERSE_MORSE.put("-..-","X");
REVERSE_MORSE.put("-.--","Y");
REVERSE_MORSE.put("--..","Z");
REVERSE_MORSE.put("..--","_");
REVERSE_MORSE.put(".-.-",",");
REVERSE_MORSE.put("---.",".");
REVERSE_MORSE.put("----","?");
}
}