Source code for submission s628

Go to diff to previous submission

Fs.java

  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. public class Fs {
  7.  
  8. // TODO Auto-generated constructor s
  9.  
  10. public static void main(String[] args) {
  11. HashMap<String, String> charToDots = new HashMap<String, String>();
  12.  
  13. charToDots.put("A",".-");
  14. charToDots.put("B", "-...");
  15. charToDots.put("C","-.-.");
  16. charToDots.put("D", "-..");
  17. charToDots.put("E",".");
  18. charToDots.put("F", "..-.");
  19. charToDots.put("G","--.");
  20. charToDots.put("H", "....");
  21. charToDots.put("I","..");
  22. charToDots.put("J", ".---");
  23. charToDots.put("K","-.-");
  24. charToDots.put("L", ".-..");
  25. charToDots.put("M","--");
  26. charToDots.put("N", "-.");
  27. charToDots.put("O","---");
  28. charToDots.put("P", ".--.");
  29. charToDots.put("Q","--.-");
  30. charToDots.put("R", ".-.");
  31. charToDots.put("S","...");
  32. charToDots.put("T", "-");
  33. charToDots.put("U","..-");
  34. charToDots.put("V", "...-");
  35. charToDots.put("W",".--");
  36. charToDots.put("X", "-..-");
  37. charToDots.put("Y","-.--");
  38. charToDots.put("Z", "--..");
  39. charToDots.put("_", "..--");
  40. charToDots.put(",",".-.-");
  41. charToDots.put(".", "---.");
  42. charToDots.put("?","----");
  43.  
  44. HashMap<String, String> dotsToChar = new HashMap<String, String>();
  45. dotsToChar.put(".-","A");
  46. dotsToChar.put("-...","B");
  47. dotsToChar.put("-.-.","C");
  48. dotsToChar.put("-..","D");
  49. dotsToChar.put(".","E");
  50. dotsToChar.put("..-.","F");
  51. dotsToChar.put("--.","G");
  52. dotsToChar.put("....","H");
  53. dotsToChar.put("..","I");
  54. dotsToChar.put(".---","J");
  55. dotsToChar.put("-.-","K");
  56. dotsToChar.put( ".-..","L");
  57. dotsToChar.put("--","M");
  58. dotsToChar.put( "-.","N");
  59. dotsToChar.put("---","O");
  60. dotsToChar.put( ".--.","P");
  61. dotsToChar.put("--.-","Q");
  62. dotsToChar.put( ".-.","R");
  63. dotsToChar.put("...","S");
  64. dotsToChar.put( "-","T");
  65. dotsToChar.put("..-","U");
  66. dotsToChar.put( "...-","V");
  67. dotsToChar.put(".--","W");
  68. dotsToChar.put( "-..-","X");
  69. dotsToChar.put("-.--","Y");
  70. dotsToChar.put("--..","Z");
  71. dotsToChar.put( "..--","_");
  72. dotsToChar.put(".-.-",",");
  73. dotsToChar.put( "---.",".");
  74. dotsToChar.put("----","?");
  75.  
  76. String line;
  77. Scanner sc = new Scanner(System.in);
  78.  
  79. while(sc.hasNext()){
  80. line = sc.nextLine();
  81. String numLine = "";
  82. String codedLine = "";
  83.  
  84. for(int i = 0; i < line.length(); i++){
  85. String tmp = charToDots.get(line.charAt(i)+"");
  86.  
  87. codedLine += tmp;
  88. numLine += ""+tmp.length();
  89. }
  90.  
  91. //System.out.println(codedLine + " " +numLine);
  92.  
  93. int index = 0;
  94. for(int i = numLine.length() - 1; i >= 0; i--){
  95. int number = Integer.parseInt(numLine.charAt(i)+"");
  96.  
  97. int result = index + number;
  98.  
  99. String substring = codedLine.substring(index,result);
  100. System.out.print(dotsToChar.get(substring));
  101.  
  102.  
  103. index = result;
  104. }
  105.  
  106. System.out.println();
  107. }
  108.  
  109.  
  110. }
  111.  
  112. }
  113.  

Diff to submission s605

Fs.java

--- c5.s605.cteam059.fs.java.0.Fs.java
+++ c5.s628.cteam059.fs.java.0.Fs.java
@@ -77,5 +77,6 @@
                 Scanner sc = new Scanner(System.in);
                 
-                while((line = sc.nextLine())!=null){
+                while(sc.hasNext()){
+                        line = sc.nextLine();
                         String numLine = "";
                         String codedLine = "";