fork download
  1. #include <unordered_map>
  2. #include <string>
  3. #include <iostream>
  4. #include <ctype.h>
  5. #include <string.h>
  6. #include <iterator>
  7.  
  8. using namespace std;
  9.  
  10. class Translator {
  11. public:
  12. void translate(string buffer)
  13. {
  14.  
  15. for (string::iterator i = buffer.begin(); i != buffer.end(); i++) {
  16. if (isalpha(*i)) {
  17. string s(1, toupper(*i));
  18. if (this->toLeetMap.find(s) != this->toLeetMap.end())
  19. cout << this->toLeetMap[s];
  20. else
  21. cout << toupper(*i);
  22. }
  23. else if (isspace(*i)) {
  24. cout << *i;
  25. }
  26. else if (isdigit(*i)) {
  27. string s(1, toupper(*i));
  28. cout << this->fromLeetMap[s];
  29. }
  30. else if (!isalpha(*i) && !isdigit(*i)) {
  31. string s;
  32. s.push_back(toupper(*i));
  33. int n = 1;
  34. string::iterator j = next(i, n);
  35. while (!isalpha(*j) && !isdigit(*j) && j != buffer.end()) {
  36. s.push_back(toupper(*j));
  37. j++;
  38. }
  39. cout << this->fromLeetMap[s];
  40. }
  41. else {
  42. cout << *i;
  43. }
  44. }
  45. }
  46.  
  47. private:
  48. unordered_map<string, string> toLeetMap = {
  49. { "A", "4" },
  50. { "B", "6" },
  51. { "E", "3" },
  52. { "I", "1" },
  53. { "L", "1" },
  54. { "M", "(V)" },
  55. { "N", "(\\)" },
  56. { "O", "0" },
  57. { "S", "5" },
  58. { "T", "7" },
  59. { "V", "\\/" },
  60. { "W", "`//" }
  61. };
  62. unordered_map<string, string> fromLeetMap = {
  63. { "4", "A" },
  64. { "6", "B" },
  65. { "3", "E" },
  66. { "1", "I" },
  67. { "1", "L" },
  68. { "(V)", "M" },
  69. { "(\\)", "N" },
  70. { "0", "O" },
  71. { "5", "S" },
  72. { "7", "T" },
  73. { "\\/", "V" },
  74. { "`//", "W" }
  75. };
  76. };
  77.  
  78. int main()
  79. {
  80. Translator translator;
  81.  
  82. while (cin) {
  83.  
  84. string buffer;
  85. getline(cin, buffer);
  86. translator.translate(buffer);
  87. cout << endl;
  88. }
  89. }
Success #stdin #stdout 0s 15248KB
stdin
I am elite.
Da pain!
Eye need help!
3Y3 (\)33d j00 t0 g37 d4 d0c70r.
1 n33d m4 p1llz!
stdout
1 4(V) 31173
684 8041(\)
3893 (\)3368 723180
E89E NEE68 74OO 7O 71ET 68A 68O67TO82
I (\)EE68 (V)A 80I1190