Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <cctype>
  5. #include <fstream>
  6. #include <vector>
  7. #include <exception>
  8.  
  9. using namespace std;
  10.  
  11. map <char, string> morze =
  12. {
  13. { 'a', ".-"},
  14. { 'b', "-..."},
  15. { 'w', ".--"},
  16. { 'g', "--."},
  17. { 'd', "-.."},
  18. { 'e', "."},
  19. { 'v', "...-"},
  20. { 'z', "--.."},
  21. { 'i', ".."},
  22. { 'j', ".---"},
  23. { 'k', "-.-"},
  24. { 'l', ".-.."},
  25. { 'm', "--"},
  26. { 'n', "-."},
  27. { 'o', "---"},
  28. { 'p', ".--."},
  29. { 'r', ".-."},
  30. { 's', "..."},
  31. { 't', "-"},
  32. { 'u', "..-"},
  33. { 'f', "..-."},
  34. { 'h', "...."},
  35. { 'c', "-.-."},
  36. { 'q', "--.-"},
  37. { 'y', "-.--"},
  38. { 'x', "-..-"},
  39. { '1', ".----"},
  40. { '2', "..---"},
  41. { '3', "...--"},
  42. { '4', "....-"},
  43. { '5', "....."},
  44. { '6', "-...."},
  45. { '7', "--..."},
  46. { '8', "---.."},
  47. { '9', "----."},
  48. { '0', "-----"},
  49. { '.', "......"},
  50. { ',', ".-.-.-"},
  51. { ':', "---..."},
  52. { ';', "-.-.-."},
  53. { '(', "-.--.-"},
  54. { ')', "-.--.-"},
  55. { '"', ".-..-."},
  56. { '-', "-....-"},
  57. { '/', "-..-."},
  58. { '?', "..--.."},
  59. { '!', "--..--"},
  60. { ' ', "-...-"},
  61. { '@', ".--.-."},
  62. };
  63.  
  64. int main()
  65. {
  66. try {
  67. vector<string> t_morze;
  68.  
  69. string line;
  70.  
  71. ifstream myfile("example.txt");
  72. if (myfile.good())
  73. {
  74. while (getline(myfile, line).good())
  75. {
  76. t_morze.push_back(line);
  77. }
  78. myfile.close();
  79. }
  80. else
  81. {
  82. throw new exception;
  83. }
  84.  
  85.  
  86. for (auto &t_m : t_morze)
  87. {
  88. line = t_m;
  89. string t;
  90. for (int i = 0; i < line.length(); i++)
  91. {
  92. line[i] = tolower(line[i]);
  93. t += morze.find(line[i])->second + " ";
  94. }
  95. t += morze.find(' ')->second + " ";
  96. t_m = t;
  97. }
  98.  
  99. ofstream myfile_out;
  100. myfile_out.open("out.txt");
  101.  
  102. for (auto &t_m : t_morze)
  103. myfile_out << t_m << "\n";
  104.  
  105. myfile_out.close();
  106.  
  107. }
  108. catch (...)
  109. {
  110. cout << "error file reading" << endl;
  111. }
  112.  
  113.  
  114.  
  115. system("PAUSE");
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement