Source code for submission s768

Go to diff to previous submission

Main.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.HashMap;
  6.  
  7. /*
  8.  * To change this template, choose Tools | Templates
  9.  * and open the template in the editor.
  10.  */
  11.  
  12. /**
  13.  *
  14.  * @author cteam028
  15.  */
  16. public class Main {
  17.  
  18. public static final String[] cm = new String[30];
  19. public static final HashMap<String, Character> hm = new HashMap<String, Character>(64);
  20. static{
  21. cm[0] = "*-";
  22. hm.put(cm[0], 'A');
  23. cm[1] = "-***";
  24. hm.put(cm[1], 'B');
  25. cm[2] = "-*-*";
  26. hm.put(cm[2], 'C');
  27. cm[3] = "-**";
  28. hm.put(cm[3], 'D');
  29. cm[4] = "*";
  30. hm.put(cm[4], 'E');
  31. cm[5] = "**-*";
  32. hm.put(cm[5], 'F');
  33. cm[6] = "--*";
  34. hm.put(cm[6], 'G');
  35. cm[7] = "****";
  36. hm.put(cm[7], 'H');
  37. cm[8] = "**";
  38. hm.put(cm[8], 'I');
  39. cm[9] = "*---";
  40. hm.put(cm[9], 'J');
  41. cm[10] = "-*-";
  42. hm.put(cm[10], 'K');
  43. cm[11] = "*-**";
  44. hm.put(cm[11], 'L');
  45. cm[12] = "--";
  46. hm.put(cm[12], 'M');
  47. cm[13] = "-*";
  48. hm.put(cm[13], 'N');
  49. cm[14] = "---";
  50. hm.put(cm[14], 'O');
  51. cm[15] = "*--*";
  52. hm.put(cm[15], 'P');
  53. cm[16] = "--*-";
  54. hm.put(cm[16], 'Q');
  55. cm[17] = "*-*";
  56. hm.put(cm[17], 'R');
  57. cm[18] = "***";
  58. hm.put(cm[18], 'S');
  59. cm[19] = "-";
  60. hm.put(cm[19], 'T');
  61. cm[20] = "**-";
  62. hm.put(cm[20], 'U');
  63. cm[21] = "***-";
  64. hm.put(cm[21], 'V');
  65. cm[22] = "*--";
  66. hm.put(cm[22], 'W');
  67. cm[23] = "-**-";
  68. hm.put(cm[23], 'X');
  69. cm[24] = "-*--";
  70. hm.put(cm[24], 'Y');
  71. cm[25] = "--**";
  72. hm.put(cm[25], 'Z');
  73. cm[26] = "**--";
  74. hm.put(cm[26], '_');
  75. cm[27] = "*-*-";
  76. hm.put(cm[27], ',');
  77. cm[28] = "---*";
  78. hm.put(cm[28], '.');
  79. cm[29] = "----";
  80. hm.put(cm[29], '?');
  81. }
  82.  
  83.  
  84.  
  85. /**
  86.   * @param args the command line arguments
  87.   */
  88. public static void main(String[] args) throws IOException {
  89. // TODO code application logic here
  90.  
  91. String line;
  92. int[] arr = new int[1024];
  93. while((line = br.readLine()) != null){
  94. StringBuilder sb = new StringBuilder(4096);
  95. int pos = 0;
  96.  
  97. for(char ch : line.toCharArray())
  98. if(ch >= 'A' && ch <= 'Z')
  99. {
  100. sb.append(cm[ch - 'A']);
  101. arr[pos++] = cm[ch - 'A'].length();
  102. }
  103. else
  104. {
  105. arr[pos++] = 4;
  106. if(ch == '_')
  107. sb.append(cm[26]);
  108. else if(ch == ',')
  109. sb.append(cm[27]);
  110. else if(ch == '.')
  111. sb.append(cm[28]);
  112. else if(ch == '?')
  113. sb.append(cm[29]);
  114. }
  115.  
  116. String s = sb.toString();
  117. pos--;
  118. char[] nn = new char[line.length()];
  119. int bot = 0;
  120. for(int nnpos = 0; pos > -1; pos--, nnpos++)
  121. {
  122. // System.err.println("bot "+bot);
  123. // System.err.println("len "+arr[pos]);
  124. final String ak = s.substring(bot, bot + arr[pos]);
  125. nn[nnpos] = hm.get(ak);
  126. bot += arr[pos];
  127. }
  128.  
  129.  
  130. System.out.println(nn);
  131.  
  132. }
  133.  
  134. }
  135.  
  136. }
  137.  

Diff to submission s744

Main.java

--- c5.s744.cteam028.fs.java.0.Main.java
+++ c5.s768.cteam028.fs.java.0.Main.java
@@ -48,5 +48,5 @@
     hm.put(cm[13], 'N');
     cm[14] = "---";
-    hm.put(cm[14], '0');
+    hm.put(cm[14], 'O');
     cm[15] = "*--*";
     hm.put(cm[15], 'P');