Source code for submission s657

Go to diff to previous submission

Main.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.io.BufferedReader;
  8. import java.io.InputStreamReader;
  9. import java.util.HashMap;
  10.  
  11. /**
  12.  *
  13.  * @author kuric10
  14.  */
  15. public class Main {
  16.  
  17. /**
  18.   * @param args the command line arguments
  19.   */
  20. public static void main(String[] args)throws Exception {
  21. // TODO code application logic here
  22. try{
  23. String s;
  24. s=input.readLine();
  25. HashMap<Character,String> dict= new HashMap<Character,String>();
  26. HashMap<String,Character> dict1= new HashMap<String,Character>();
  27. //dict.put(s, input)
  28.  
  29. dict.put('A', ".-");
  30. dict.put('B', "-...");
  31. dict.put('C', "-.-.");
  32. dict.put('D', "-..");
  33. dict.put('E', ".");
  34. dict.put('F', "..-.");
  35. dict.put('G', "--.");
  36. dict.put('H', "....");
  37. dict.put('I', "..");
  38. dict.put('J', ".---");
  39. dict.put('K', "-.-");
  40. dict.put('L', ".-..");
  41. dict.put('M', "--");
  42. dict.put('N', "-.");
  43. dict.put('O', "---");
  44. dict.put('P', ".--.");
  45. dict.put('Q', "--.-");
  46. dict.put('R', ".-.");
  47. dict.put('S', "...");
  48. dict.put('T', "-");
  49. dict.put('U', "..-");
  50. dict.put('V', "...-");
  51. dict.put('W', ".--");
  52. dict.put('X', "-..-");
  53. dict.put('Y', "-.--");
  54. dict.put('Z', "--..");
  55. dict.put('_', "..--");
  56. dict.put(',', ".-.-");
  57. dict.put('.', "---.");
  58. dict.put('?', "----");
  59.  
  60. dict1.put( ".-",'A');
  61. dict1.put( "-...",'B');
  62. dict1.put("-.-.",'C' );
  63. dict1.put( "-..",'D');
  64. dict1.put(".",'E' );
  65. dict1.put("..-.",'F' );
  66. dict1.put("--.",'G' );
  67. dict1.put("....",'H' );
  68. dict1.put( "..",'I');
  69. dict1.put(".---",'J' );
  70. dict1.put( "-.-",'K');
  71. dict1.put(".-..",'L' );
  72. dict1.put("--",'M' );
  73. dict1.put("-.",'N' );
  74. dict1.put("---",'O' );
  75. dict1.put(".--.",'P' );
  76. dict1.put("--.-",'Q' );
  77. dict1.put(".-.",'R' );
  78. dict1.put("...",'S' );
  79. dict1.put("-",'T' );
  80. dict1.put("..-",'U' );
  81. dict1.put( "...-",'V');
  82. dict1.put(".--",'W' );
  83. dict1.put( "-..-",'X');
  84. dict1.put("-.--",'Y' );
  85. dict1.put("--..",'Z' );
  86. dict1.put( "..--",'_');
  87. dict1.put( ".-.-",',');
  88. dict1.put( "---.",'.');
  89. dict1.put( "----",'?');
  90. int counter;
  91. StringBuilder kluc=new StringBuilder();
  92. StringBuilder rev= new StringBuilder();
  93. String text,key;
  94. int pomocna;
  95. while(!s.equals(null)){
  96. counter=0;
  97. for (int i = 0; i < s.length(); i++) {
  98. rev.append(dict.get(s.charAt(i)));
  99. kluc.append(dict.get(s.charAt(i)).length());
  100.  
  101. }
  102. text=rev.toString();
  103. //
  104. kluc.reverse();
  105. key=kluc.toString();
  106. for (int i = 0; i < key.length(); i++) {
  107. pomocna=(key.charAt(i))-48;
  108. System.out.print(dict1.get(text.substring(counter,counter+pomocna)));
  109. counter+=pomocna;
  110. }
  111.  
  112. System.out.println();
  113. rev= new StringBuilder();
  114. kluc= new StringBuilder();
  115. s=input.readLine();
  116. }
  117. }catch(Exception e){
  118.  
  119. }
  120. }
  121. }
  122.  

Diff to submission s654

Main.java

--- c5.s654.cteam085.fs.java.0.Main.java
+++ c5.s657.cteam085.fs.java.0.Main.java
@@ -20,5 +20,5 @@
     public static void main(String[] args)throws Exception {
         // TODO code application logic here
-        
+        try{
         BufferedReader input= new BufferedReader(new InputStreamReader(System.in));
         String s;
@@ -116,4 +116,7 @@
             s=input.readLine();
         }
+        }catch(Exception e){
+            
+        }
     }
 }