fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. string s; cin >> s;
  8. int n = s.size(), cursor = n;
  9. int m; cin >> m;
  10.  
  11. for(int i=0; i<m; i++){
  12. string input; cin>>input;
  13. if(input == "L"&&cursor>0) cursor--;
  14. else if(input == "D"&&cursor<n) cursor++;
  15. else if(input == "B"&&cursor>0) {
  16. s.erase(cursor-1);
  17. n--; cursor--;
  18. }
  19. else if(input == "P"){
  20. string c; cin >> c;
  21. s.insert(cursor,c);
  22. n++; cursor++;
  23. }
  24.  
  25. //cout << cursor << '\n' << n << '\n' << s << '\n';
  26.  
  27. }
  28. cout << s;
  29. }
Runtime error #stdin #stdout #stderr 0.01s 5444KB
stdin
dmih
11
B
B
P x
L
B
B
B
P y
D
D
P z
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 2) > this->size() (which is 1)