/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 432.0 KiB
#3 Accepted 126ms 3.258 MiB
#4 Accepted 75ms 7.117 MiB
#5 Accepted 1ms 768.0 KiB
#6 Accepted 141ms 2.141 MiB
#7 Accepted 130ms 1.895 MiB
#8 Accepted 25ms 1.012 MiB
#9 Accepted 100ms 7.922 MiB
#10 Accepted 126ms 7.934 MiB
#11 Accepted 39ms 3.52 MiB
#12 Accepted 81ms 7.371 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-10-03 13:08:37
Judged By
Score
100
Total Time
141ms
Peak Memory
7.934 MiB