Fs.java
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author cteam023
*/
public class Fs {
private static void vyres
(String radek
){ Kod morse = new Kod(radek);
// morse.debugVypis();
morse.otocCislo();
}
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in); while(sc.hasNextLine()){
radek = sc.nextLine();
vyres(radek);
}
}
private static class Kod{
private String morseovka
= "";
private static final String[] tableToMorse
= {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
private static final HashMap
<String, Character
> morseToTable
;
static {
morseToTable
= new HashMap
<String, Character
>(); char pocitadlo = 'A';
morseToTable.put(s, pocitadlo++);
}
morseToTable.put("..--", '_');
morseToTable.put("---.", '.');
morseToTable.put(".-.-", ',');
morseToTable.put("----", '?');
}
for (char c: retezec.toCharArray()){
toMorse(c);
}
}
private void toMorse(char c){
if (c >= 'A' && c <= 'Z'){
String pridat
= tableToMorse
[c
- 'A']; morseovka += pridat;
cislice += "" + pridat.length();
} else {
if (c == '_'){
morseovka += "..--";
} else if (c == '.'){
morseovka += "---.";
} else if (c == ','){
morseovka += ".-.-";
} else if (c == '?'){
morseovka += "----";
}
cislice += "4";
}
}
public void debugVypis(){
System.
out.
println("m:" + morseovka
+", " + cislice
); }
public void otocCislo(){
for (int i = 0; i < cislice.length(); i++){
reverse = cislice.charAt(i) + reverse;
}
cislice = reverse;
}
@Override
int pocitadloCisel = 0;
int ukazatelSekvenci = 0;
while (pocitadloCisel < cislice.length()){
sub = morseovka.substring(ukazatelSekvenci, ukazatelSekvenci + cislice.charAt(pocitadloCisel) - '0');
ukazatelSekvenci += cislice.charAt(pocitadloCisel++) - '0';
sekvence += morseToTable.get(sub);
}
return sekvence;
}
}
}