Advertisement
Dzham

Untitled

Feb 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. std::string s;
  6. std::cin >> s;
  7. std::string result = "";
  8. bool inserting = false;
  9. int pos = 0;
  10. for (int i = 0; i < s.size(); ++i) {
  11. if (inserting) {
  12. if (s.size() - i >= 5 && s.substr(i, 5) == "<ESC>") {
  13. inserting = false;
  14. i += 4;
  15. } else {
  16. result = result.substr(0, pos) + s[i] + result.substr(pos, result.size() - pos);
  17. pos++;
  18. }
  19. } else {
  20. if (s[i] == 'i') {
  21. inserting = true;
  22. } else if (s[i] == 'h' && pos > 0) {
  23. pos--;
  24. } else if (s[i] == 'l' && pos < result.size() - 1) {
  25. pos++;
  26. }
  27. }
  28. }
  29. std::cout << result << '\n';
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement