Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <fstream>
- #include <locale>
- #include <sstream>
- #include <algorithm>
- #include <Windows.h>
- #include <vector>
- using namespace std;
- string tolower(string& word) {
- transform(word.begin(), word.end(), word.begin(), [](unsigned char c) { return std::tolower(c); });
- return word;
- }
- void PrintVector(const vector<string>& v) {
- for (const auto& x : v)
- cout << x << ' ';
- cout << endl;
- }
- vector<string> translate(vector<string> v, map<string, string> m) {
- vector<string> rus;
- for (const auto& x : v)
- if (m.count(x) > 0)
- rus.push_back(m[x]);
- else
- rus.push_back(x);
- return rus;
- }
- int main()
- {
- setlocale(0, "rus");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- ifstream fin("translate.txt", ios::in | ios::binary);
- map<string, string> translator;
- string line;
- string en, ru;
- string s;
- while (getline(fin, line)) {
- int tmp = line.find(' ');
- en = line.substr(0, tmp);
- ru = line.substr(tmp + 1, line.size());
- translator.insert({ en , ru });
- }
- cout << "Введите слова: ";
- cin >> s;
- getline(std::cin, s);
- stringstream ss(s);
- vector<string> vec;
- while (ss >> s) vec.push_back(tolower(s));
- PrintVector(translate(vec, translator));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement