push to debug

This commit is contained in:
Borean 2025-01-12 15:50:45 +01:00
parent cff475a854
commit deebdedc1b
2 changed files with 23 additions and 4 deletions

View file

@ -16,7 +16,7 @@ std::string Morse_code::encode(const std::string &str) {
std::string res;
for (auto &c : str) {
auto it = morse_map.find(c);
auto it = morse_map.find(toupper(c)); // convert
if (it != morse_map.end()) {
res += it->second + " ";
}
@ -24,6 +24,22 @@ std::string Morse_code::encode(const std::string &str) {
return res;
}
// std::string Morse_code::decode(const std::string &str) {
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<char, std::string> &p) {
return p.second == s;
});
if (it != morse_map.end()) {
res += it->first;
} else {
res += '?';
}
}
return res;
}

View file

@ -2,13 +2,16 @@
#include <string>
#include <map>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <sstream>
class Morse_code
{
public:
Morse_code(std::string filename);
std::string encode(const std::string &str);
std::string decode(const std::string &str);
std::string decode(std::string str);
private:
std::map<char, std::string> morse_map;
};