push to debug
This commit is contained in:
		
							parent
							
								
									cff475a854
								
							
						
					
					
						commit
						deebdedc1b
					
				
					 2 changed files with 23 additions and 4 deletions
				
			
		|  | @ -16,7 +16,7 @@ std::string Morse_code::encode(const std::string &str) { | ||||||
|     std::string res; |     std::string res; | ||||||
| 
 | 
 | ||||||
|     for (auto &c : str) { |     for (auto &c : str) { | ||||||
|         auto it = morse_map.find(c); |         auto it = morse_map.find(toupper(c)); // convert
 | ||||||
|         if (it != morse_map.end()) { |         if (it != morse_map.end()) { | ||||||
|             res += it->second + " "; |             res += it->second + " "; | ||||||
|         } |         } | ||||||
|  | @ -24,6 +24,22 @@ std::string Morse_code::encode(const std::string &str) { | ||||||
|     return res; |     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; | ||||||
|  | } | ||||||
|  | @ -2,13 +2,16 @@ | ||||||
| #include <string> | #include <string> | ||||||
| #include <map> | #include <map> | ||||||
| #include <fstream> | #include <fstream> | ||||||
|  | #include <iostream> | ||||||
|  | #include <algorithm> | ||||||
|  | #include <sstream> | ||||||
| 
 | 
 | ||||||
| class Morse_code | class Morse_code | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     Morse_code(std::string filename); |     Morse_code(std::string filename); | ||||||
|     std::string encode(const std::string &str); |     std::string encode(const std::string &str); | ||||||
|     std::string decode(const std::string &str); |     std::string decode(std::string str); | ||||||
| private: | private: | ||||||
|     std::map<char, std::string> morse_map; |     std::map<char, std::string> morse_map; | ||||||
| }; | }; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Borean
						Borean