/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 121ms 3.273 MiB
#4 Accepted 71ms 7.176 MiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 133ms 2.277 MiB
#7 Accepted 125ms 2.133 MiB
#8 Accepted 24ms 1.062 MiB
#9 Accepted 92ms 7.996 MiB
#10 Accepted 130ms 7.883 MiB
#11 Accepted 37ms 3.543 MiB
#12 Accepted 77ms 7.238 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(n)  n.begin(),n.end()
#define sz(n) (ll) n.size()
#define endl '\n'
const double PI = 3.14159265358979323846;
const ll mod = 1e9 + 7;


void test_case() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> front, back;
    for (char c : s) {
        back.push_back(c);
    }
    bool check = false;
    while (q--) {
        int x;
        cin >> x;
        if (x == 1) {
            check = !check;
        } else if (x == 2) {
            int d;
            char c;
            cin >> d >> c;
            if (check) {
                if (d == 1) {
                    back.push_back(c);
                } else {
                    front.push_front(c);
                }
            } else {
                if (d == 1) {
                    front.push_front(c);
                } else {
                    back.push_back(c);
                }
            }
        }
    }
    if (check) {
        for (auto it = back.rbegin(); it != back.rend(); ++it) {
            cout << *it;
        }
        for (auto it = front.rbegin(); it != front.rend(); ++it) {
            cout << *it;
        }
    } else {
        for (char c : front) {
            cout << c;
        }
        for (char c : back) {
            cout << c;
        }
    }
    cout << endl;
}


int32_t main() {
    //freopen("input.txt","r", stdin);
    //freopen("output.txt","w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    cin >> t;
    while(t--) {
        test_case();
    }
}

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:13:10
Judged At
2024-09-05 16:13:10
Judged By
Score
100
Total Time
133ms
Peak Memory
7.996 MiB