35657

Untitled

Jul 28th, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <map>
  7. #include <Windows.h>
  8. #include <fstream>
  9.  
  10. int main() {
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);
  13.  
  14.     std::ifstream fin("eng-rus dictionary.txt");
  15.     std::ofstream fout("rus-eng dictionary.txt");
  16.  
  17.     if (!fin.is_open() || !fout.is_open()) {
  18.         std::cout << "Ошибка открытия файла";
  19.     }
  20.     else {
  21.         std::string word, translation;
  22.         std::map<std::string, std::string> dictionary;
  23.  
  24.         while (!fin.eof()) {
  25.             fin >> word >> translation;
  26.             dictionary[translation] = word;
  27.         }
  28.         for (auto a : dictionary) {
  29.             fout << a.first;
  30.             for (int i = 0; i < 20 - a.first.size(); i++) {
  31.                 fout << " ";
  32.             }
  33.             fout << a.second << std::endl;
  34.         }
  35.         fin.close();
  36.         fout.close();
  37.     }
  38. }
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment