Naxocist

BananaDonation

Apr 1st, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endll '\n'
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.    
  8.     int n; cin >> n;
  9.  
  10.     deque<pair<int, int> > dq;
  11.    
  12.     char c;
  13.  
  14.     while(n--){
  15.         int x, y;
  16.         scanf(" %c", &c);
  17.         if(c == 'A'){
  18.             scanf("%d,%d", &x, &y);
  19.             dq.push_back({x, y});
  20.  
  21.         }else if(c == 'B'){
  22.             scanf("%d,%d", &x, &y);
  23.             dq.push_front({x, y});
  24.  
  25.         }else if(c == 'C'){
  26.             if(!dq.empty()) dq.pop_front();
  27.  
  28.         }else if(c == 'D'){
  29.             if(!dq.empty()) dq.pop_back();
  30.  
  31.         }else if(c == 'E'){
  32.             sort(dq.begin(), dq.end());
  33.  
  34.         }else if(c == 'F'){
  35.             sort(dq.begin(), dq.end(), greater<>());
  36.  
  37.         }else{
  38.             scanf("%d", &x);
  39.             printf("{%d,%d}\n", dq[x-1].first, dq[x-1].second);
  40.         }
  41.        
  42.     }
  43.    
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment