Advertisement
35657

Untitled

Sep 28th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 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::vector<std::pair<std::string, std::string>> dict;
  25.  
  26.         std::pair<std::string, std::string> temp;
  27.  
  28.         fin >> temp.first >> temp.second;
  29.         while (!fin.eof()) {
  30.             dict.push_back(temp);
  31.             fin >> temp.first >> temp.second;
  32.         }
  33.  
  34.         std::sort(dict.begin(), dict.end(), [](const std::pair<std::string, std::string> & left, const std::pair<std::string, std::string> & right) {
  35.             return left.second < right.second;
  36.             });
  37.  
  38.         for (const auto& a : dict) {
  39.             fout << a.second;
  40.             for (int i = 0; i < 20 - a.second.size(); i++) {
  41.                 fout << " ";
  42.             }
  43.             fout << a.first << std::endl;
  44.         }
  45.    
  46.         fin.close();
  47.         fout.close();
  48.     }
  49.  
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement