fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cctype>
  4. #include <map>
  5.  
  6. std::map<std::string, std::string> dict {
  7. {"A", "4"},
  8. {"B", "6"},
  9. {"E", "3"},
  10. {"I", "1"},
  11. {"L", "|"},
  12. {"M", "(V)"},
  13. {"N", "(\\)"},
  14. {"O", "0"},
  15. {"S", "5"},
  16. {"T", "7"},
  17. {"U", "\\/"},
  18. {"W", "`//"}
  19. };
  20.  
  21. bool is_l33t(const std::string& input)
  22. {
  23. for(const auto& kv: dict)
  24. if(input.find(kv.second) != std::string::npos)
  25. return true;
  26. return false;
  27. }
  28.  
  29. std::string search_replace(std::string source, const std::string& haystack, const std::string& needle)
  30. {
  31. int idx;
  32. while((idx = source.find(haystack)) != std::string::npos)
  33. {
  34. source = source.replace(idx, haystack.length(), needle);
  35. }
  36. return source;
  37. }
  38.  
  39. int main()
  40. {
  41. std::string line;
  42. while(getline(std::cin, line))
  43. {
  44. std::transform(line.begin(), line.end(), line.begin(), ::toupper);
  45. std::cout << line << " -> ";
  46. bool l33t = is_l33t(line);
  47. for(const auto& kv: dict)
  48. {
  49. std::string from = l33t ? kv.second : kv.first;
  50. std::string to = l33t ? kv.first : kv.second;
  51. line = search_replace(line, from, to);
  52. //std::cout << "\t" << line << std::endl;
  53. }
  54. std::cout << line << std::endl;
  55. }
  56. return 0;
  57. }
Success #stdin #stdout 0s 15248KB
stdin
31337
storm
I am elite.
Da pain!
Eye need help!
3Y3 (\)33d j00 t0 g37 d4 d0c70r.
1 n33d m4 p1llz!
stdout
31337 -> EIEET
STORM -> 570R(V)
I AM ELITE. -> 1 4(V) 3|173.
DA PAIN! -> D4 P41(\)!
EYE NEED HELP! -> 3Y3 (\)33D H3|P!
3Y3 (\)33D J00 T0 G37 D4 D0C70R. -> EYE NEED JOO TO GET DA DOCTOR.
1 N33D M4 P1LLZ! -> I NEED MA PILLZ!