Source code for submission s584

Go to diff to previous submission

FS.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package fs;
  6.  
  7. import java.util.Scanner;
  8. import java.util.TreeMap;
  9.  
  10. /**
  11.  *
  12.  * @author drevenak3
  13.  */
  14. public class FS {
  15.  
  16. public static void main(String[] args) {
  17. Scanner vst=new Scanner(System.in);
  18. TreeMap<Character,String> Morse=new TreeMap<Character,String>();
  19. Morse.put('A', ".-");
  20. Morse.put('B', "-...");
  21. Morse.put('C', "-.-.");
  22. Morse.put('D', "-..");
  23. Morse.put('E', ".");
  24. Morse.put('F', "..-.");
  25. Morse.put('G', "--.");
  26. Morse.put('H', "....");
  27. Morse.put('I', "..");
  28. Morse.put('J', ".---");
  29. Morse.put('K', "-.-");
  30. Morse.put('L', ".-..");
  31. Morse.put('M', "--");
  32. Morse.put('N', "-.");
  33. Morse.put('O', "---");
  34. Morse.put('P', ".--.");
  35. Morse.put('Q', "--.-");
  36. Morse.put('R', ".-.");
  37. Morse.put('S', "...");
  38. Morse.put('T', "-");
  39. Morse.put('U', "..-");
  40. Morse.put('V', "...-");
  41. Morse.put('W', ".--");
  42. Morse.put('X', "-..-");
  43. Morse.put('Y', "-.--");
  44. Morse.put('Z', "--..");
  45. Morse.put('_', "..--");
  46. Morse.put(',', ".-.-");
  47. Morse.put('.', "---.");
  48. Morse.put('?', "----");
  49. TreeMap<String,Character> MorseInv=new TreeMap<String,Character>();
  50. MorseInv.put(".-",'A');
  51. MorseInv.put("-...",'B');
  52. MorseInv.put("-.-.",'C');
  53. MorseInv.put("-..",'D');
  54. MorseInv.put(".",'E');
  55. MorseInv.put("..-.",'F');
  56. MorseInv.put("--.",'G');
  57. MorseInv.put("....",'H');
  58. MorseInv.put("..",'I');
  59. MorseInv.put(".---",'J');
  60. MorseInv.put("-.-",'K');
  61. MorseInv.put(".-..",'L');
  62. MorseInv.put("--",'M');
  63. MorseInv.put("-.",'N');
  64. MorseInv.put("---",'O');
  65. MorseInv.put(".--.",'P');
  66. MorseInv.put("--.-",'Q');
  67. MorseInv.put(".-.",'R');
  68. MorseInv.put("...",'S');
  69. MorseInv.put("-",'T');
  70. MorseInv.put("..-",'U');
  71. MorseInv.put("...-",'V');
  72. MorseInv.put(".--",'W');
  73. MorseInv.put("-..-",'X');
  74. MorseInv.put("-.--",'Y');
  75. MorseInv.put("--..",'Z');
  76. MorseInv.put("..--",'_');
  77. MorseInv.put(".-.-",',');
  78. MorseInv.put("---.",'.');
  79. MorseInv.put("----",'?');
  80. while(vst.hasNext()){
  81. String msgEnc=vst.next();
  82. int cisla[]=new int[msgEnc.length()];
  83. StringBuilder msgDec=new StringBuilder();
  84. for(int i=0;i<msgEnc.length();++i){
  85. char c=msgEnc.charAt(i);
  86. String code=Morse.get(c);
  87. msgDec.append(code);
  88. int j=msgEnc.length()-i-1;
  89. cisla[j]=code.length();
  90. }
  91. int zac=0;
  92. for(int i=0;i<msgEnc.length();++i){
  93. String code=msgDec.substring(zac,zac+cisla[i]);
  94. zac+=cisla[i];
  95. char c=MorseInv.get(code);
  96. System.out.print(c);
  97. }
  98. System.out.println();
  99. }
  100. vst.close();
  101. }
  102. }
  103.  

Diff to submission s564

FS.java

--- c5.s564.cteam083.fs.java.0.FS.java
+++ c5.s584.cteam083.fs.java.0.FS.java
@@ -5,7 +5,4 @@
 package fs;
 
-//import java.io.File;
-//import java.io.FileNotFoundException;
-//import java.util.ArrayList;
 import java.util.Scanner;
 import java.util.TreeMap;
@@ -17,11 +14,7 @@
 public class FS {
 
-    /**
-     * @param args the command line arguments
-     */
     public static void main(String[] args) {
-        // TODO code application logic her
         Scanner vst=new Scanner(System.in);
-        TreeMap<Character,String> Morse=new TreeMap<>();
+        TreeMap<Character,String> Morse=new TreeMap<Character,String>();
         Morse.put('A', ".-");
         Morse.put('B', "-...");
@@ -54,5 +47,5 @@
         Morse.put('.', "---.");
         Morse.put('?', "----");
-        TreeMap<String,Character> MorseInv=new TreeMap<>();
+        TreeMap<String,Character> MorseInv=new TreeMap<String,Character>();
         MorseInv.put(".-",'A');
         MorseInv.put("-...",'B');