Amonin

Untitled

Dec 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. using namespace std;
  7. vector<pair<string, int>> ignor_register(vector<pair<string, int>>& text) {
  8.     vector<pair<string, int>> new_v = {text[0]};
  9.     string new_string1 = "";
  10.     string new_string2 = "";
  11.     for (int i = 0; i < text.size() - 1; ++i) {
  12.         new_string1 = "";
  13.         for (char c : text[i].first) {
  14.             new_string1 += tolower(c);
  15.         }
  16.         new_string2 = "";
  17.         for (char c : text[i + 1].first) {
  18.             new_string2 += tolower(c);
  19.         }
  20.         if (new_string1 == new_string2) {
  21.             new_v[new_v.size() - 1].second += text[i + 1].second;
  22.         } else {
  23.             new_v.push_back(pair<string, int>(text[i + 1].first, text[i + 1].second));
  24.         }
  25.     }
  26.     return new_v;
  27. }
  28. int main() {
  29.     vector<int> split_req;
  30.     vector<pair<string, int>> text;
  31.     string request;
  32.     getline(cin, request);
  33.     for (int i = 0; i < request.length(); i += 3) {
  34.         if (request[i + 1] == 'i') {
  35.             split_req.push_back(0);
  36.         } else if (request[i + 1] == 'c') {
  37.             split_req.push_back(3);
  38.         } else if (request[i + 1] == 'd') {
  39.             split_req.push_back(2);
  40.         } else if (request[i + 1] == 'u') {
  41.             split_req.push_back(1);
  42.         }
  43.     }
  44.     string str;
  45.     string old_str;
  46.     getline(cin, old_str);
  47.     int cnt = 1;
  48.     while (getline(cin, str)) {
  49.         if (str != old_str) {
  50.             text.push_back(pair<string, int>(old_str, cnt));
  51.             cnt = 1;
  52.             old_str = str;
  53.         } else {
  54.             ++cnt;
  55.         }
  56.     }
  57.     if (str != old_str) {
  58.         text.push_back(pair<string, int>(old_str, cnt));
  59.         cnt = 1;
  60.         old_str = str;
  61.     }
  62.     bool output = false;
  63.     int flag = 0;
  64.     sort(split_req.begin(), split_req.end());
  65.     for (int i : split_req) {
  66.         if (i == 0) {
  67.             text = ignor_register(text);
  68.         } else if (i == 1) {
  69.             flag += 1;
  70.         } else if (i == 2) {
  71.             flag += 2;
  72.         } else if (i == 3) {
  73.             output = true;
  74.         }
  75.     }
  76.     if (output) {
  77.         if (flag == 0) {
  78.             for (auto pair : text) {
  79.                 cout << pair.second << " " << pair.first << endl;
  80.             }
  81.         } else if (flag == 1) {
  82.             for (auto pair : text) {
  83.                 if (pair.second == 1) {
  84.                     cout << pair.second << " " << pair.first << endl;
  85.                 }
  86.             }
  87.         } else if (flag == 2) {
  88.             for (auto pair : text) {
  89.                 if (pair.second != 1) {
  90.                     cout << pair.second << " " << pair.first << endl;
  91.                 }
  92.             }
  93.         }
  94.     }
  95.     else {
  96.         if (flag == 0) {
  97.             for (auto pair : text) {
  98.                 cout << pair.first << endl;
  99.             }
  100.         }
  101.         else if (flag == 1) {
  102.             for (auto pair : text) {
  103.                 if (pair.second == 1) {
  104.                     cout << pair.first << endl;
  105.                 }
  106.             }
  107.         }
  108.         else if (flag == 2) {
  109.             for (auto pair : text) {
  110.                 if (pair.second != 1) {
  111.                     cout << pair.first << endl;
  112.                 }
  113.             }
  114.         }
  115.     }
  116.     system("pause");
  117. }
Advertisement
Add Comment
Please, Sign In to add comment