Advertisement
Guest User

C

a guest
Jan 16th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <fstream>
  6. #include <cctype>
  7. #include <numeric>
  8. using namespace std;
  9. int transfer(char c) {
  10.     return c - '0';
  11. }
  12. struct Command
  13. {
  14.     string inp;
  15.     bool is_add;
  16.     int add;
  17. };
  18. int Conc(int cur, char c) {
  19.     return cur * 10 + transfer(c);
  20. }
  21. template<typename T>
  22. void del(basic_string<T>& s,
  23.     const basic_string<T>& action) {
  24.     string::size_type cur = action.length();
  25.  
  26.     for (string::size_type it = s.find(action);
  27.         it != basic_string<T>::npos;
  28.         it = s.find(action))
  29.         s.erase(it, cur);
  30. }
  31. void add(string & LineNumbers,string & crack1,string & crack2, string & s,string & action)
  32. {
  33.     int IteratorAdd = accumulate(LineNumbers.begin(), LineNumbers.end(), 0, Conc);
  34.     IteratorAdd--;
  35.     for (int j = 0; j < IteratorAdd; ++j)
  36.     {
  37.         crack1 += s[j];
  38.     }
  39.     for (int j = IteratorAdd; j < s.length(); ++j)
  40.     {
  41.         crack2 += s[j];
  42.     }
  43.     s = crack1 + action + crack2;
  44. }
  45. void show(string & s)
  46. {
  47.     cout << s;
  48. }
  49. int main()
  50. {
  51.     string s, temp;
  52.     int am;
  53.     cin >> s;
  54.     cin >> am;
  55.     cin.ignore();
  56.     vector<string> a;
  57.     bool itsnumber = 0;
  58.     bool watch_out = 0;
  59.     for (int i = 0; i < am; ++i)
  60.     {
  61.         getline(cin, temp);
  62.         a.push_back(temp);
  63.     }
  64.     for (int it = 0; it < am; ++it)
  65.     {
  66.         string LineNumbers, crack1, crack2,action;
  67.         temp = a[it];
  68.         itsnumber = 0;
  69.         for (int i = 0; i < a[it].length(); ++i)
  70.         {
  71.             if (!itsnumber && temp[i] != ' ')
  72.             {
  73.                 action += temp[i];
  74.             }
  75.             if (temp[i] == ' ' && !itsnumber)
  76.             {
  77.                 itsnumber = 1;
  78.             }
  79.             if (itsnumber && temp[i] != ' ')
  80.             {
  81.                 LineNumbers += temp[i];
  82.             }
  83.         }
  84.         if (itsnumber)
  85.         {
  86.             add(LineNumbers, crack1, crack2, s, action);
  87.         }
  88.         else
  89.         {
  90.             del(s, action);
  91.         }
  92.     }
  93.     show(s);
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement