Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- using namespace std;
- class Vim {
- private:
- list<char> res;
- size_t iter = 0;
- bool status = 0;
- public:
- void Move_h() {
- if (iter != 0)
- --iter;
- }
- void Move_l() {
- if (iter != res.size())
- ++iter;
- }
- void Paste(char c) {
- if (!res.empty()) {
- auto x = res.begin();
- advance(x, iter);
- res.insert(x, c);
- ++iter;
- } else {
- res.push_back(c);
- ++iter;
- }
- }
- bool Status() {
- return status;
- }
- void Switch_stat_to_View() {
- status = 0;
- }
- void Switch_stat_to_Edit() {
- status = 1;
- }
- list<char> &Out() {
- return res;
- }
- };
- int main() {
- string str;
- Vim result;
- cin >> str;
- for (auto i = 0; i != str.size(); ++i) {
- if (result.Status()) {
- if (str[i] != '<') {
- result.Paste(str[i]);
- } else {
- result.Switch_stat_to_View();
- i += 4;
- }
- } else {
- if (str[i] == 'h') {
- result.Move_h();
- } else if (str[i] == 'l') {
- result.Move_l();
- } else if (str[i] == 'i') {
- result.Switch_stat_to_Edit();
- }
- }
- }
- list<char> ans;
- ans = result.Out();
- for (auto i : ans) {
- cout << i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement