/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 114ms 3.422 MiB
#4 Accepted 61ms 7.246 MiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 129ms 2.555 MiB
#7 Accepted 122ms 2.098 MiB
#8 Accepted 25ms 1.051 MiB
#9 Accepted 81ms 7.785 MiB
#10 Accepted 105ms 7.789 MiB
#11 Accepted 34ms 3.59 MiB
#12 Accepted 65ms 7.137 MiB

Code

#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

typedef long long int ll ;
//typedef __int128 lll;
#define pb push_back
#define pinf   2e18
#define ninf   -2e18
#define PI    acos(-1.0)
#define endl  "\n"
#define F first
#define S second

//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd (ll a,ll b) {
    if(a%b==0)return b;
    return gcd(b,a%b);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //inout() ;

    ll t,i,j ;
    cin>>t ;
    while(t--) {
        string s,fs,ls;
        bool ok=true;
        cin>>s;
        string ss=s;
        reverse(s.begin(),s.end());
        ll q,i;
        cin>>q;
        while(q--) {
            ll k,l;
            char c;
            cin>>k;
            if(k==1) {
                ok=ok?false:true;
            }
            else {
                cin>>l>>c;
                if(ok) {
                    if(l==1) {
                        fs.push_back(c);
                    }
                    else {
                        ls.push_back(c);
                    }
                }
                else
                {
                    if(l==2) {
                        fs.push_back(c);
                    }
                    else {
                        ls.push_back(c);
                    }
                }
            }
        }
        if(ok){
         for(i=fs.size()-1;i>=0;i--)cout<<fs[i];
         for(auto it: ss)cout<<it;
         for(auto it: ls)cout<<it;
        }
        else
        {
         for(i=ls.size()-1;i>=0;i--)cout<<ls[i];
         for(auto it: s)cout<<it;
         for(i=0;i<fs.size();i++)cout<<fs[i];
        }
        cout<<'\n';









    }
    return 0 ;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:52:49
Judged At
2024-09-05 16:52:49
Judged By
Score
100
Total Time
129ms
Peak Memory
7.789 MiB