1 solutions

  • 0
    @ 2024-09-05 21:18:25
    #include <bits/stdc++.h>
    using namespace std;
    #define SC               scanf
    #define PF               printf
    #define ull              unsigned long long
    #define ld               long double
    #define F                first
    #define S                second
    #define pb               push_back
    #define sort_a(a)        sort(a.begin(),a.end());
    #define sort_d(a)        sort(a.rbegin(),a.rend());
    #define READ(f)          freopen(f, "r", stdin)
    #define WRITE(f)         freopen(f, "w", stdout)
    #define rev(s)           reverse(s.begin(),s.end())
    #define P(ok)            cout << (ok ? "YES\n": "NO\n")
    #define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
    #define ll long long
    typedef pair< ll , ll>                   PII;
    void solve()
    {
       string s ; cin >> s ;
       deque < char > dq ;
       for(auto it : s) dq.pb(it) ;
       int q ; cin >> q ;
       bool rev = 0 ;
       while(q--){
        int ty , f ; cin >> ty ;
        char ch ;
        if(ty == 1) rev ^= 1 ;
        else {
            cin >> f >> ch ;
            if(f == 1 ){
                if(rev) dq.pb(ch) ;
                else dq.push_front(ch) ;
            }
            else {
                if(rev) dq.push_front(ch) ;
                else dq.pb(ch) ;
            }
        }
       }
       if(rev) reverse(dq.begin() , dq.end()) ;
       for(auto it : dq) cout << it ; cout << "\n" ;
    }
    int main()
    {
         __Heart__
         //WRITE("output10.txt") ;
         //READ("input10.txt") ;
         int t ; cin >> t ; while(t--) solve() ;
    }
    
    
    
  • 1

Information

ID
1088
Difficulty
4
Category
Queue , Beginners Click to Show
Tags
# Submissions
103
Accepted
44
Accepted Ratio
43%
Uploaded By