fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.nio.file.*;
  7. import java.util.stream.*;
  8. import java.util.regex.Pattern;
  9.  
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Morse
  13. {
  14.  
  15. private static final Map<String, String> morseAlphabet = new HashMap<>();
  16.  
  17. static {
  18. morseAlphabet.put("", " ");
  19. morseAlphabet.put(".-", "A");
  20. morseAlphabet.put("-...", "B");
  21. morseAlphabet.put("-.-.", "C");
  22. morseAlphabet.put("-..", "D");
  23. morseAlphabet.put(".", "E");
  24. morseAlphabet.put("..-.", "F");
  25. morseAlphabet.put("--.", "G");
  26. morseAlphabet.put("....", "H");
  27. morseAlphabet.put("..", "I");
  28. morseAlphabet.put(".---", "J");
  29. morseAlphabet.put("-.-", "K");
  30. morseAlphabet.put(".-..", "L");
  31. morseAlphabet.put("--", "M");
  32. morseAlphabet.put("-.", "N");
  33. morseAlphabet.put("---", "O");
  34. morseAlphabet.put(".--.", "P");
  35. morseAlphabet.put("--.-", "Q");
  36. morseAlphabet.put(".-.", "R");
  37. morseAlphabet.put("...", "S");
  38. morseAlphabet.put("-", "T");
  39. morseAlphabet.put("..-", "U");
  40. morseAlphabet.put("...-", "V");
  41. morseAlphabet.put(".--", "W");
  42. morseAlphabet.put("-..-", "X");
  43. morseAlphabet.put("-.--", "Y");
  44. morseAlphabet.put("--..", "Z");
  45. morseAlphabet.put("-----", "0");
  46. morseAlphabet.put(".----", "1");
  47. morseAlphabet.put("..---", "2");
  48. morseAlphabet.put("...--", "3");
  49. morseAlphabet.put("....-", "4");
  50. morseAlphabet.put(".....", "5");
  51. morseAlphabet.put("-....", "6");
  52. morseAlphabet.put("--...", "7");
  53. morseAlphabet.put("---..", "8");
  54. morseAlphabet.put("----.", "9");
  55. }
  56.  
  57.  
  58. private static final Pattern charsplit = Pattern.compile(" ");
  59.  
  60. private static final String decodeLine(String line) {
  61. return charsplit.splitAsStream(line)
  62. .map(letter -> morseAlphabet.get(letter))
  63. .collect(Collectors.joining(""));
  64. }
  65.  
  66. public static final String decode(List<String> data) {
  67. String output = data.stream()
  68. .map(Morse::decodeLine)
  69. .collect(Collectors.joining("\n"));
  70. return output;
  71. }
  72.  
  73. public static void main (String[] args) throws java.lang.Exception
  74. {
  75. String out = Morse.decode(Arrays.asList("-.-. --- -.. . .-. . ...- .. . .--", "..--- -. -.. -- --- -. .. - --- .-.", "..-. .-. --- -- -.-. --- -.. . . ...- .- .-.."));
  76. System.out.println(out);
  77. }
  78.  
  79. }
Success #stdin #stdout 0.22s 320832KB
stdin
Standard input is empty
stdout
CODE REVIEW
2ND MONITOR
FROM CODEEVAL