Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <map>
- using namespace std;
- vector<pair<string, int>> ignor_register(vector<pair<string, int>>& text) {
- vector<pair<string, int>> new_v = {text[0]};
- string new_string1 = "";
- string new_string2 = "";
- for (int i = 0; i < text.size() - 1; ++i) {
- new_string1 = "";
- for (char c : text[i].first) {
- new_string1 += tolower(c);
- }
- new_string2 = "";
- for (char c : text[i + 1].first) {
- new_string2 += tolower(c);
- }
- if (new_string1 == new_string2) {
- new_v[new_v.size() - 1].second += text[i + 1].second;
- } else {
- new_v.push_back(pair<string, int>(text[i + 1].first, text[i + 1].second));
- }
- }
- return new_v;
- }
- int main() {
- vector<int> split_req;
- vector<pair<string, int>> text;
- string request;
- getline(cin, request);
- for (int i = 0; i < request.length(); i += 3) {
- if (request[i + 1] == 'i') {
- split_req.push_back(0);
- } else if (request[i + 1] == 'c') {
- split_req.push_back(3);
- } else if (request[i + 1] == 'd') {
- split_req.push_back(2);
- } else if (request[i + 1] == 'u') {
- split_req.push_back(1);
- }
- }
- string str;
- string old_str;
- getline(cin, old_str);
- int cnt = 1;
- while (getline(cin, str)) {
- if (str != old_str) {
- text.push_back(pair<string, int>(old_str, cnt));
- cnt = 1;
- old_str = str;
- } else {
- ++cnt;
- }
- }
- if (str != old_str) {
- text.push_back(pair<string, int>(old_str, cnt));
- cnt = 1;
- old_str = str;
- }
- bool output = false;
- int flag = 0;
- sort(split_req.begin(), split_req.end());
- for (int i : split_req) {
- if (i == 0) {
- text = ignor_register(text);
- } else if (i == 1) {
- flag += 1;
- } else if (i == 2) {
- flag += 2;
- } else if (i == 3) {
- output = true;
- }
- }
- if (output) {
- if (flag == 0) {
- for (auto pair : text) {
- cout << pair.second << " " << pair.first << endl;
- }
- } else if (flag == 1) {
- for (auto pair : text) {
- if (pair.second == 1) {
- cout << pair.second << " " << pair.first << endl;
- }
- }
- } else if (flag == 2) {
- for (auto pair : text) {
- if (pair.second != 1) {
- cout << pair.second << " " << pair.first << endl;
- }
- }
- }
- }
- else {
- if (flag == 0) {
- for (auto pair : text) {
- cout << pair.first << endl;
- }
- }
- else if (flag == 1) {
- for (auto pair : text) {
- if (pair.second == 1) {
- cout << pair.first << endl;
- }
- }
- }
- else if (flag == 2) {
- for (auto pair : text) {
- if (pair.second != 1) {
- cout << pair.first << endl;
- }
- }
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment