Advertisement
nsnikolova1

2

May 15th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5. #include <stack>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     std::ios_base::sync_with_stdio(false); //io optimization
  11.     std::cin.tie(nullptr); //io optimization
  12.  
  13.     string input, line, word, newString, comand, Nstr;
  14.     int BeginPos, EndPos, PastPos;
  15.     stack<string> setWord;
  16.  
  17.     //vhod
  18.  
  19.     getline(cin, input);
  20.  
  21.     while (getline(cin, comand))
  22.     {
  23.  
  24.         istringstream line(comand);
  25.         line >> word;
  26.         //comand Copy
  27.         if (word == "copy")
  28.         {
  29.             line >> BeginPos;
  30.             line >> EndPos;
  31.             while ((BeginPos > 0) && isalpha(input[BeginPos]))
  32.             {
  33.                
  34.                 BeginPos--;
  35.                
  36.             }
  37.             if (input[BeginPos] == ' ') BeginPos ++;
  38.            
  39.            
  40.             while ((EndPos <input.size()-1) && isalpha(input[EndPos]))
  41.             {
  42.                 EndPos++;
  43.             }
  44.             if (EndPos >= input.size() - 1) EndPos = input.size();
  45.  
  46.             newString = input.substr(BeginPos,( (EndPos )- BeginPos) );
  47.             setWord.emplace(newString);
  48.  
  49.          }
  50.         else if (word == "paste")
  51.         {
  52.             line >> PastPos;
  53.             if (!setWord.empty())
  54.             {
  55.                 Nstr = setWord.top();
  56.                 setWord.pop();
  57.             }
  58.             else break;
  59.  
  60.             if (input[PastPos] == ' ')
  61.                 input.insert(PastPos,' '+Nstr);
  62.             else
  63.                 input.insert(PastPos, Nstr);
  64.  
  65.  
  66.         }
  67.         else if (word == "end")
  68.         {
  69.             cout << input;
  70.             break;
  71.         }
  72.  
  73.     }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement