Source code for submission s795

fs.java

  1. import java.util.Scanner;
  2.  
  3.  
  4. public class fs {
  5.  
  6. private String in;
  7. private StringBuilder temp;
  8. private int[] pole;
  9. private String[] vzor = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
  10. "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--",
  11. "-..-","-.--","--..","..--","---.",".-.-","----"};
  12.  
  13. public fs(){
  14. Scanner s = new Scanner(System.in);
  15. while(s.hasNext()){
  16. in = s.next();
  17. temp = new StringBuilder("");
  18. pole = new int[in.length()];
  19. ries();
  20. }
  21.  
  22. s.close();
  23. }
  24.  
  25. private void ries() {
  26. strToMorse();
  27. morseToStr();
  28. }
  29.  
  30.  
  31. private void morseToStr() {
  32. int zac = 0;
  33. String pom;
  34. for (int i = 0; i < pole.length; i++) {
  35. pom = temp.substring(zac, zac+pole[i]);
  36. zac = zac+pole[i];
  37. int index = 0;
  38. for (int j = 0; j < vzor.length; j++) {
  39. if(pom.equals(vzor[j])){
  40. index = j;
  41. break;
  42. }
  43. }
  44. if(index == 26) {
  45. System.out.print("_");
  46. } else {
  47. if(index == 27) {
  48. System.out.print(".");
  49. } else {
  50. if(index == 28) {
  51. System.out.print(",");
  52. } else {
  53. if(index == 29) {
  54. System.out.print("?");
  55. } else {
  56. System.out.print((char)(index+65));
  57. }
  58. }
  59. }
  60. }
  61. }
  62. System.out.println();
  63. }
  64.  
  65. private void strToMorse() {
  66. for (int i = 0; i < in.length(); i++) {
  67. if(in.charAt(i) == '_' ){
  68. temp.append("..--");
  69. pole[in.length()-1-i] = 4;
  70. } else {
  71. if(in.charAt(i) == '.' ){
  72. temp.append("---.");
  73. pole[in.length()-1-i] = 4;
  74. } else {
  75. if(in.charAt(i) == ',' ){
  76. temp.append(".-.-");
  77. pole[in.length()-1-i] = 4;
  78. } else {
  79. if(in.charAt(i) == '?' ){
  80. temp.append("----");
  81. pole[in.length()-1-i] = 4;
  82. } else {
  83. temp.append(vzor[in.charAt(i)-65]);
  84. pole[in.length()-1-i] = vzor[in.charAt(i)-65].length();
  85. }
  86. }
  87. }
  88. }
  89. }
  90.  
  91. }
  92.  
  93. public static void main(String[] args) {
  94. fs f = new fs();
  95. }
  96.  
  97. }
  98.