Source code for submission s631

fs.cpp

  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <sstream>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. #define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
  16. #define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--)
  17. #define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
  18.  
  19. #define PB push_back
  20. #define MP make_pair
  21.  
  22. #define MM(co, cim) memset((co), (cim), sizeof((co)))
  23.  
  24. #define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
  25.  
  26. map<string,char> to;
  27. map<char, string> rev;
  28. map<char, int> from;
  29. vector<int> code;
  30. string line, conv;
  31.  
  32. map<string,char>::iterator it;
  33. map<char, int>::iterator itt;
  34.  
  35. int main ()
  36. {
  37. to.insert(MP(".-", 'A'));
  38. to.insert(MP("-...", 'B'));
  39. to.insert(MP("-.-.", 'C'));
  40. to.insert(MP("-..", 'D'));
  41. to.insert(MP(".", 'E'));
  42. to.insert(MP("..-.", 'F'));
  43. to.insert(MP("--.", 'G'));
  44. to.insert(MP("....", 'H'));
  45. to.insert(MP("..", 'I'));
  46. to.insert(MP(".---", 'J'));
  47. to.insert(MP("-.-", 'K'));
  48. to.insert(MP(".-..", 'L'));
  49. to.insert(MP("--", 'M'));
  50. to.insert(MP("-.", 'N'));
  51. to.insert(MP("---", 'O'));
  52. to.insert(MP(".--.", 'P'));
  53. to.insert(MP("--.-", 'Q'));
  54. to.insert(MP(".-.", 'R'));
  55. to.insert(MP("...", 'S'));
  56. to.insert(MP("-", 'T'));
  57. to.insert(MP("..-", 'U'));
  58. to.insert(MP("...-", 'V'));
  59. to.insert(MP(".--", 'W'));
  60. to.insert(MP("-..-", 'X'));
  61. to.insert(MP("-.--", 'Y'));
  62. to.insert(MP("--..", 'Z'));
  63. to.insert(MP("..--", '_'));
  64. to.insert(MP(".-.-", ','));
  65. to.insert(MP("---.", '.'));
  66. to.insert(MP("----", '?'));
  67.  
  68.  
  69. for (it = to.begin(); it != to.end(); it++) rev.insert(MP(it->second, it->first));
  70. for (it = to.begin(); it != to.end(); it++) from.insert(MP(it->second, it->first.length()));
  71.  
  72. while (getline(cin, line))
  73. {
  74. code.clear();
  75. conv.clear();
  76. FOR(i, 0, line.length())
  77. {
  78. itt = from.find(line[i]);
  79. code.PB(itt->second);
  80. conv += rev.find(itt->first)->second;
  81. }
  82. int pl = 0;
  83. FORDE(i, code.size() - 1, 0)
  84. {
  85. string tmp;
  86. tmp.clear();
  87. FOR(j, 0, code[i]) tmp += conv[pl + j];
  88. cout << to.find(tmp)->second;
  89. pl += code[i];
  90. }
  91. cout << endl;
  92. }
  93.  
  94. return 0;
  95. }
  96.