Source code for submission s461

fs.cpp

  1. #include<iostream>
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. #include<math.h>
  7. #include<string.h>
  8.  
  9. #include<vector>
  10. #include<map>
  11. #include<string>
  12. #include<algorithm>
  13.  
  14. using namespace std;
  15.  
  16. #define FOR(i,a,b) for(int i=a; i<=b; i++)
  17. #define FOREACH(obj, it) for(__typeof(obj.begin()) it = (obj).begin(); it != (obj).end(); (it)++)
  18.  
  19. #define PII pair<int, int>
  20. #define MP make_pair
  21. #define PB push_back
  22.  
  23. #define SIZE(s) ((int)(s).size())
  24.  
  25. #define ll long long
  26. #define fi first
  27. #define se second
  28.  
  29. map<char, string> M1;
  30. map<string, char> M2;
  31.  
  32. void init()
  33. {
  34. M1['A'] = ".-";
  35. M1['B'] = "-...";
  36. M1['C'] = "-.-.";
  37. M1['D'] = "-..";
  38. M1['E'] = ".";
  39. M1['F'] = "..-.";
  40. M1['G'] = "--.";
  41. M1['H'] = "....";
  42. M1['I'] = "..";
  43. M1['J'] = ".---";
  44. M1['K'] = "-.-";
  45. M1['L'] = ".-..";
  46. M1['M'] = "--";
  47. M1['N'] = "-.";
  48. M1['O'] = "---";
  49. M1['P'] = ".--.";
  50. M1['Q'] = "--.-";
  51. M1['R'] = ".-.";
  52. M1['S'] = "...";
  53. M1['T'] = "-";
  54. M1['U'] = "..-";
  55. M1['V'] = "...-";
  56. M1['W'] = ".--";
  57. M1['X'] = "-..-";
  58. M1['Y'] = "-.--";
  59. M1['Z'] = "--..";
  60. M1['_'] = "..--";
  61. M1[','] = ".-.-";
  62. M1['.'] = "---.";
  63. M1['?'] = "----";
  64. FOREACH(M1, it)
  65. M2[ it->se ] = it->fi;
  66. }
  67.  
  68. #define MAX 1047
  69. char s[MAX];
  70.  
  71. int dlzky[MAX];
  72.  
  73. int main()
  74. {
  75. string n = "";
  76. init();
  77. int N;
  78. while(gets(s))
  79. {
  80. n = "";
  81. N = (int) strlen(s);
  82. FOR(i,0,N-1)
  83. {
  84. n+= M1[s[i]];
  85. dlzky[i] = SIZE( M1[s[i]] );
  86. }
  87. string temp;
  88. int k = 0;
  89. string ns = "";
  90. for(int i=N-1;i>=0;i--)
  91. {
  92. temp = n.substr(k , dlzky[i]);
  93. ns+= M2[temp];
  94. k+= dlzky[i];
  95. }
  96. printf("%s\n", ns.c_str());
  97. }
  98. return 0;
  99. }
  100.  
  101.