Advertisement
Okorosso

Untitled

Mar 23rd, 2021
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <Windows.h>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct myMap {
  10.     std::string key;
  11.     std::string value;
  12. };
  13.  
  14. bool myComp(const myMap &a, const myMap &b) {
  15.     return a.key.length() > b.key.length();
  16. }
  17.  
  18. int main() {
  19.     /*setlocale(LC_ALL, "ru_RU");*/
  20.     SetConsoleCP(1251);
  21.     SetConsoleOutputCP(1251);
  22.  
  23.     int count_el, count_str;
  24.     cin >> count_el >> count_str;
  25.     vector<myMap> mp(count_el);
  26.     string a;
  27.     getline(cin, a);
  28.  
  29.     for (int i = 0; i < count_el; i++) {
  30.         getline(cin, mp[i].key);
  31.         getline(cin, mp[i].value);
  32.  
  33.     }
  34.     sort(mp.begin(), mp.end(), myComp);
  35.     string main_str;
  36.  
  37.  
  38.     for (int i = 0; i < count_str + 1; i++) {
  39.         string tmp;
  40.         getline(cin, tmp);
  41.         main_str += tmp + '\n';
  42.     }
  43.  
  44.     for (int i = 0; i < mp.size(); i++) {
  45.         int left;
  46.         cout << mp[i].key << '\n';
  47.         do {
  48.             left = main_str.find(mp[i].key);
  49.             if (left != -1) {
  50.                 main_str.replace(left, mp[i].key.length(), (string) mp[i].value);
  51.             }
  52.         } while (left != -1);
  53.  
  54.  
  55.     }
  56.  
  57.     cout << main_str;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement