Source code for submission s630

fs.cpp

  1. //
  2. // File: fs.cc
  3. // Author: cteam030
  4. //
  5. // Created on October 19, 2013, 11:06 AM
  6. //
  7.  
  8. #include <stdlib.h>
  9. #include <iostream>
  10. #include <string>
  11. #include <map>
  12. #include <sstream>
  13.  
  14. using namespace std;
  15.  
  16. //
  17. //
  18. //
  19. int main(int argc, char** argv) {
  20.  
  21. map<char, string> t2m;
  22. map<string, string> m2t;
  23.  
  24. t2m['A'] = ".-";
  25. t2m['B'] = "-...";
  26. t2m['C'] = "-.-.";
  27. t2m['D'] = "-..";
  28. t2m['E'] = ".";
  29. t2m['F'] = "..-.";
  30. t2m['G'] = "--.";
  31. t2m['H'] = "....";
  32. t2m['I'] = "..";
  33. t2m['J'] = ".---";
  34. t2m['K'] = "-.-";
  35. t2m['L'] = ".-..";
  36. t2m['M'] = "--";
  37. t2m['N'] = "-.";
  38. t2m['O'] = "---";
  39. t2m['P'] = ".--.";
  40. t2m['Q'] = "--.-";
  41. t2m['R'] = ".-.";
  42. t2m['S'] = "...";
  43. t2m['T'] = "-";
  44. t2m['U'] = "..-";
  45. t2m['V'] = "...-";
  46. t2m['W'] = ".--";
  47. t2m['X'] = "-..-";
  48. t2m['Y'] = "-.--";
  49. t2m['Z'] = "--..";
  50. t2m['_'] = "..--";
  51. t2m[','] = ".-.-";
  52. t2m['.'] = "---.";
  53. t2m['?'] = "----";
  54.  
  55.  
  56. m2t[".-"] = "A";
  57. m2t["-..."] = "B";
  58. m2t["-.-."] = "C";
  59. m2t["-.."] = "D";
  60. m2t["."] = "E";
  61. m2t["..-."] = "F";
  62. m2t["--."] = "G";
  63. m2t["...."] ="H" ;
  64. m2t[".."] = "I";
  65. m2t[".---"] = "J";
  66. m2t["-.-"] = "K";
  67. m2t[".-.."] = "L";
  68. m2t["--"] = "M";
  69. m2t["-."] = "N";
  70. m2t["---"] = "O";
  71. m2t[".--."] = "P";
  72. m2t["--.-"] = "Q";
  73. m2t[".-."] = "R";
  74. m2t["..."] = "S";
  75. m2t["-"] = "T";
  76. m2t["..-"] = "U";
  77. m2t["...-"] = "V";
  78. m2t[".--"] = "W";
  79. m2t["-..-"] = "X";
  80. m2t["-.--"] = "Y";
  81. m2t["--.."] = "Z";
  82. m2t["..--"] = "_";
  83. m2t[".-.-"] = ",";
  84. m2t["---."] = ".";
  85. m2t["----"] = "?";
  86.  
  87.  
  88.  
  89. string line;
  90. while(cin >> line) {
  91. stringstream morse;
  92. morse.clear();
  93. int pos[line.length()];
  94. for(size_t i=0; i<line.length();i++) {
  95. morse << t2m[line[i]];
  96. pos[i] = t2m[line[i]].length();
  97. }
  98. int off=0;
  99. string sMorse = morse.str();
  100. stringstream out;
  101. out.clear();
  102. for(int i=line.length()-1; i>=0; i--) {
  103. string tmp = sMorse.substr(off, pos[i]);
  104. out << m2t[tmp];
  105. off += pos[i];
  106. }
  107. cout << out.str() << "\n";
  108. }
  109.  
  110. return (0);
  111. }
  112.  
  113.