Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <vector>
- #include <fstream>
- #include <cctype>
- #include <numeric>
- using namespace std;
- int transfer(char c) {
- return c - '0';
- }
- struct Command
- {
- string inp;
- bool is_add;
- int add;
- };
- int Conc(int cur, char c) {
- return cur * 10 + transfer(c);
- }
- template<typename T>
- void del(basic_string<T>& s,
- const basic_string<T>& action) {
- string::size_type cur = action.length();
- for (string::size_type it = s.find(action);
- it != basic_string<T>::npos;
- it = s.find(action))
- s.erase(it, cur);
- }
- void add(string & LineNumbers,string & crack1,string & crack2, string & s,string & action)
- {
- int IteratorAdd = accumulate(LineNumbers.begin(), LineNumbers.end(), 0, Conc);
- IteratorAdd--;
- for (int j = 0; j < IteratorAdd; ++j)
- {
- crack1 += s[j];
- }
- for (int j = IteratorAdd; j < s.length(); ++j)
- {
- crack2 += s[j];
- }
- s = crack1 + action + crack2;
- }
- void show(string & s)
- {
- cout << s;
- }
- int main()
- {
- string s, temp;
- int am;
- cin >> s;
- cin >> am;
- cin.ignore();
- vector<string> a;
- bool itsnumber = 0;
- bool watch_out = 0;
- for (int i = 0; i < am; ++i)
- {
- getline(cin, temp);
- a.push_back(temp);
- }
- for (int it = 0; it < am; ++it)
- {
- string LineNumbers, crack1, crack2,action;
- temp = a[it];
- itsnumber = 0;
- for (int i = 0; i < a[it].length(); ++i)
- {
- if (!itsnumber && temp[i] != ' ')
- {
- action += temp[i];
- }
- if (temp[i] == ' ' && !itsnumber)
- {
- itsnumber = 1;
- }
- if (itsnumber && temp[i] != ' ')
- {
- LineNumbers += temp[i];
- }
- }
- if (itsnumber)
- {
- add(LineNumbers, crack1, crack2, s, action);
- }
- else
- {
- del(s, action);
- }
- }
- show(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement