69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <algorithm>
|
|
|
|
// mapa znakow
|
|
std::unordered_map<char, std::string> morseCode = {
|
|
{'a', ".-"},
|
|
{'ą', ".-.-"},
|
|
{'b', "-..."},
|
|
{'c', "-.-."},
|
|
{'ć', "-.-.."},
|
|
{'d', "-.."},
|
|
{'e', "."},
|
|
{'ę', "..-.."},
|
|
{'f', "..-."},
|
|
{'g', "--."},
|
|
{'h', "...."},
|
|
{'i', ".."},
|
|
{'j', ".---"},
|
|
{'k', "-.-"},
|
|
{'l', ".-.."},
|
|
{'ł', ".-..-"},
|
|
{'m', "--"},
|
|
{'n', "-."},
|
|
{'ń', "--.--"},
|
|
{'o', "---"},
|
|
{'ó', "---."},
|
|
{'p', ".--."},
|
|
{'q', "--.-"},
|
|
{'r', ".-."},
|
|
{'s', "..."},
|
|
{'ś', "...-..."},
|
|
{'t', "-"},
|
|
{'u', "..-"},
|
|
{'v', "...-"},
|
|
{'w', ".--"},
|
|
{'x', "-..-"},
|
|
{'y', "-.--"},
|
|
{'z', "--.."},
|
|
{'ź', "--..-."},
|
|
{'ż', "--..-"}
|
|
};
|
|
|
|
void encode(std::string word) {
|
|
std::string output;
|
|
for (char ch : word) {
|
|
if (morseCode.find(ch) != morseCode.end()) {
|
|
output += morseCode[ch] + " "; //koduj
|
|
} else if (ch == ' ') {
|
|
output += " / "; // odziel slowa
|
|
} else {
|
|
output += "?"; // nw co to za znak
|
|
std::cout << " Uwaga! W twojej wiadomosci pojawily sie nieoczekiwane znaki, uzyj tylko znakow polskiego alfabetu.";
|
|
}
|
|
}
|
|
std::cout << "Kod morse'a: " << output << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
std::string input;
|
|
std::cout << "Wprowadz slowo do zakodowania: ";
|
|
std::getline(std::cin, input);
|
|
// zmieniam na male litery
|
|
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
|
|
// wywolaj i wyswietl w f. void
|
|
encode(input);
|
|
return 0;
|
|
} |