#include "morse_code.h" Morse_code::Morse_code(std::string filename) { std::ifstream in(filename); char c; while (in >> c) { std::string s; in >> s; morse_map.insert(std::make_pair(c, s)); // gay ass } } std::string Morse_code::encode(const std::string &str) { std::string res; for (auto &c : str) { auto it = morse_map.find(toupper(c)); // convert if (it != morse_map.end()) { res += it->second + " "; } } return res; } std::string Morse_code::decode(std::string str) { std::stringstream in(str); std::string res; std::string s; while(in >> s) { auto it = std::find_if(morse_map.begin(), morse_map.end(), [&](std::pair &p) { return p.second == s; }); if (it != morse_map.end()) { res += it->first; } else { res += '?'; } } return res; }