35657

Untitled

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