Advertisement
dimon-torchila

Untitled

Sep 9th, 2022
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <fstream>
  5. #include <locale>
  6. #include <sstream>
  7. #include <algorithm>
  8. #include <Windows.h>
  9. #include <vector>
  10.  
  11. using namespace std;
  12.  
  13. string tolower(string& word) {
  14.     transform(word.begin(), word.end(), word.begin(), [](unsigned char c) { return std::tolower(c); });
  15.     return word;
  16. }
  17.  
  18. void PrintVector(const vector<string>& v) {
  19.     for (const auto& x : v)
  20.         cout << x << ' ';
  21.     cout << endl;
  22. }
  23.  
  24. vector<string> translate(vector<string> v, map<string, string> m) {
  25.     vector<string> rus;
  26.     for (const auto& x : v)
  27.         if (m.count(x) > 0)
  28.             rus.push_back(m[x]);
  29.         else
  30.             rus.push_back(x);
  31.     return rus;
  32. }
  33.  
  34. int main()
  35. {
  36.     setlocale(0, "rus");
  37.     SetConsoleCP(1251);
  38.     SetConsoleOutputCP(1251);
  39.     ifstream fin("translate.txt", ios::in | ios::binary);
  40.     map<string, string> translator;
  41.     string line;
  42.     string en, ru;
  43.     string s;
  44.     while (getline(fin, line)) {
  45.         int tmp = line.find(' ');
  46.         en = line.substr(0, tmp);
  47.         ru = line.substr(tmp + 1, line.size());
  48.         translator.insert({ en , ru });
  49.     }
  50.     cout << "Введите слова: ";
  51.     cin >> s;
  52.     getline(std::cin, s);
  53.     stringstream ss(s);
  54.     vector<string> vec;
  55.     while (ss >> s) vec.push_back(tolower(s));
  56.     PrintVector(translate(vec, translator));
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement