Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Vim {
  8. private:
  9. list<char> res;
  10. size_t iter = 0;
  11. bool status = 0;
  12.  
  13. public:
  14. void Move_h() {
  15. if (iter != 0)
  16. --iter;
  17. }
  18.  
  19. void Move_l() {
  20. if (iter != res.size())
  21. ++iter;
  22. }
  23.  
  24. void Paste(char c) {
  25. if (!res.empty()) {
  26. auto x = res.begin();
  27. advance(x, iter);
  28. res.insert(x, c);
  29. ++iter;
  30. } else {
  31. res.push_back(c);
  32. ++iter;
  33. }
  34. }
  35.  
  36. bool Status() {
  37. return status;
  38. }
  39.  
  40. void Switch_stat_to_View() {
  41. status = 0;
  42. }
  43.  
  44. void Switch_stat_to_Edit() {
  45. status = 1;
  46. }
  47.  
  48.  
  49. list<char> &Out() {
  50. return res;
  51. }
  52. };
  53.  
  54. int main() {
  55. string str;
  56. Vim result;
  57. cin >> str;
  58. for (auto i = 0; i != str.size(); ++i) {
  59. if (result.Status()) {
  60. if (str[i] != '<') {
  61. result.Paste(str[i]);
  62. } else {
  63. result.Switch_stat_to_View();
  64. i += 4;
  65. }
  66. } else {
  67. if (str[i] == 'h') {
  68. result.Move_h();
  69. } else if (str[i] == 'l') {
  70. result.Move_l();
  71. } else if (str[i] == 'i') {
  72. result.Switch_stat_to_Edit();
  73. }
  74. }
  75. }
  76. list<char> ans;
  77. ans = result.Out();
  78. for (auto i : ans) {
  79. cout << i;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement