/*
* CTU Open 2013
* HES
*/
package template;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
/**
*
* @author cteam007
*/
public class Fs {
}
while (!st.hasMoreTokens()) {
}
return st.nextToken();
}
return Integer.
parseInt(nextToken
()); }
static Map
<String, String
> morseMap
;
/**
* @param args the command line arguments
*/
morseMap
= new HashMap
<String, String
>();
morseMap.put(".-", "A");
morseMap.put("-...", "B");
morseMap.put("-.-.", "C");
morseMap.put("-..", "D");
morseMap.put(".", "E");
morseMap.put("..-.", "F");
morseMap.put("--.", "G");
morseMap.put("....", "H");
morseMap.put("..", "I");
morseMap.put(".---", "J");
morseMap.put("-.-", "K");
morseMap.put(".-..", "L");
morseMap.put("--", "M");
morseMap.put("-.", "N");
morseMap.put("---", "O");
morseMap.put(".--.", "P");
morseMap.put("--.-", "Q");
morseMap.put(".-.", "R");
morseMap.put("...", "S");
morseMap.put("-", "T");
morseMap.put("..-", "U");
morseMap.put("...-", "V");
morseMap.put(".--", "W");
morseMap.put("-..-", "X");
morseMap.put("-.--", "Y");
morseMap.put("--..", "Z");
morseMap.put("..--", "_");
morseMap.put(".-.-", ",");
morseMap.put("---.", ".");
morseMap.put("----", "?");
Fs instance = new Fs();
while (instance.run()) {
}
}
if (in == null) {
return false;
}
useLine(in);
String cryptedString
= nextToken
();
Stack<Integer> intStack = toStack(cryptedString);
String cryptedMorse
= toMorse
(cryptedString
);
int offset = 0;
while (!intStack.empty()) {
int len = intStack.pop();
System.
out.
print(decodeMorse
(parseMorse
(cryptedMorse, offset, len
))); offset += len;
}
return true;
}
Stack
<Integer
> toStack
(String cryptedText
) { Stack<Integer> stack = new Stack<Integer>();
int count = cryptedText.length();
for (int i = 0; i < count; i++) {
stack.add(morse(cryptedText.charAt(i)).length());
}
return stack;
}
int count = cryptedText.length();
for (int i = 0; i < count; i++) {
morseT += morse(cryptedText.charAt(i));
}
return morseT;
}
String parseMorse
(String cryptedText,
int offset,
int length
) { return cryptedText.substring(offset, offset + length);
}
switch (c) {
case 'A':
return ".-";
case 'B':
return "-...";
case 'C':
return "-.-.";
case 'D':
return "-..";
case 'E':
return ".";
case 'F':
return "..-.";
case 'G':
return "--.";
case 'H':
return "....";
case 'I':
return "..";
case 'J':
return ".---";
case 'K':
return "-.-";
case 'L':
return ".-..";
case 'M':
return "--";
case 'N':
return "-.";
case 'O':
return "---";
case 'P':
return ".--.";
case 'Q':
return "--.-";
case 'R':
return ".-.";
case 'S':
return "...";
case 'T':
return "-";
case 'U':
return "..-";
case 'V':
return "...-";
case 'W':
return ".--";
case 'X':
return "-..-";
case 'Y':
return "-.--";
case 'Z':
return "--..";
case '_':
return "..--";
case ',':
return ".-.-";
case '.':
return "---.";
case '?':
return "----";
}
return "";
}
return morseMap.get(morse);
}
}