Advertisement
cosenza987

Untitled

Aug 7th, 2021
1,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     int n, p;
  9.     cin >> n >> p;
  10.     list<int> l;
  11.     for(int i = 0; i < n; i++) {
  12.         int k;
  13.         cin >> k;
  14.         l.push_back(k);
  15.     }
  16.     auto it = l.begin();
  17.     advance(it, p - 1);
  18.     int q;
  19.     cin >> q;
  20.     while(q--) {
  21.         string s;
  22.         cin >> s;
  23.         if(s == "moveLeft") {
  24.             if(it != l.begin()) {
  25.                 it--;
  26.             }
  27.         } else if(s == "moveRight") {
  28.             it++;
  29.             if(it == l.end()) {
  30.                 it--;
  31.             }
  32.         } else if(s == "insertLeft") {
  33.             int k;
  34.             cin >> k;
  35.             l.insert(it, k);
  36.             //it++;
  37.         } else if(s == "insertRight") {
  38.             int k;
  39.             cin >> k;
  40.             it++;
  41.             l.insert(it, k);
  42.             it--;
  43.         } else if(s == "print") {
  44.             cout << *it << "\n";
  45.         }
  46.         /*for(auto k : l) {
  47.             cout << k << " ";
  48.         }
  49.         cout << "\n";*/
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement