Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <cctype>
- #include <fstream>
- #include <vector>
- #include <exception>
- using namespace std;
- map <char, string> morze =
- {
- { 'a', ".-"},
- { 'b', "-..."},
- { 'w', ".--"},
- { 'g', "--."},
- { 'd', "-.."},
- { 'e', "."},
- { 'v', "...-"},
- { 'z', "--.."},
- { 'i', ".."},
- { 'j', ".---"},
- { 'k', "-.-"},
- { 'l', ".-.."},
- { 'm', "--"},
- { 'n', "-."},
- { 'o', "---"},
- { 'p', ".--."},
- { 'r', ".-."},
- { 's', "..."},
- { 't', "-"},
- { 'u', "..-"},
- { 'f', "..-."},
- { 'h', "...."},
- { 'c', "-.-."},
- { 'q', "--.-"},
- { 'y', "-.--"},
- { 'x', "-..-"},
- { '1', ".----"},
- { '2', "..---"},
- { '3', "...--"},
- { '4', "....-"},
- { '5', "....."},
- { '6', "-...."},
- { '7', "--..."},
- { '8', "---.."},
- { '9', "----."},
- { '0', "-----"},
- { '.', "......"},
- { ',', ".-.-.-"},
- { ':', "---..."},
- { ';', "-.-.-."},
- { '(', "-.--.-"},
- { ')', "-.--.-"},
- { '"', ".-..-."},
- { '-', "-....-"},
- { '/', "-..-."},
- { '?', "..--.."},
- { '!', "--..--"},
- { ' ', "-...-"},
- { '@', ".--.-."},
- };
- int main()
- {
- try {
- vector<string> t_morze;
- string line;
- ifstream myfile("example.txt");
- if (myfile.good())
- {
- while (getline(myfile, line).good())
- {
- t_morze.push_back(line);
- }
- myfile.close();
- }
- else
- {
- throw new exception;
- }
- for (auto &t_m : t_morze)
- {
- line = t_m;
- string t;
- for (int i = 0; i < line.length(); i++)
- {
- line[i] = tolower(line[i]);
- t += morze.find(line[i])->second + " ";
- }
- t += morze.find(' ')->second + " ";
- t_m = t;
- }
- ofstream myfile_out;
- myfile_out.open("out.txt");
- for (auto &t_m : t_morze)
- myfile_out << t_m << "\n";
- myfile_out.close();
- }
- catch (...)
- {
- cout << "error file reading" << endl;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement