fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. static std::map<std::string, char> const MorseMap = {
  5. {".-", 'A'},
  6. {"-...", 'B'},
  7. {"-.-.", 'C'},
  8. {"-..", 'D'},
  9. {".", 'E'},
  10. {".._.", 'F'},
  11. {"--.", 'G'},
  12. {"....", 'H'},
  13. {"..", 'I'},
  14. {".---", 'J'},
  15. {"-.-", 'K'},
  16. {".-..", 'L'},
  17. {"--", 'M'},
  18. {"-.", 'N'},
  19. {"---", 'O'},
  20. {".--.", 'P'},
  21. {"--.-", 'Q'},
  22. {".-.", 'R'},
  23. {"...", 'S'},
  24. {"-", 'T'},
  25. {"..-", 'U'},
  26. {"...-", 'V'},
  27. {".--", 'W'},
  28. {"-..-", 'X'},
  29. {"-.--", 'Y'},
  30. {"--..", 'Z'},
  31. {"-----", '0'},
  32. {".----", '1'},
  33. {"..---", '2'},
  34. {"...--", '3'},
  35. {"....-", '4'},
  36. {".....", '5'},
  37. {"-....", '6'},
  38. {"--...", '7'},
  39. {"---..", '8'},
  40. {"----.", '9'}
  41. };
  42.  
  43. void convert(std::istream& morse, std::ostream& regular) {
  44. std::string buffer;
  45. while (morse >> buffer) {
  46. auto const it = MorseMap.find(buffer);
  47.  
  48. if (it == MorseMap.end()) { regular << '?'; continue; }
  49.  
  50. regular << it->second;
  51. }
  52. }
  53.  
  54. int main() {
  55. convert(std::cin, std::cout);
  56. return 0;
  57. }
Success #stdin #stdout 0s 3436KB
stdin
-- .- .-. -.- ------ -- .- .-. -.-
stdout
MARK?MARK