/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 552.0 KiB
#3 Accepted 136ms 3.246 MiB
#4 Accepted 81ms 7.246 MiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 152ms 2.301 MiB
#7 Accepted 139ms 1.895 MiB
#8 Accepted 28ms 1.043 MiB
#9 Accepted 104ms 7.945 MiB
#10 Accepted 132ms 7.742 MiB
#11 Accepted 41ms 3.668 MiB
#12 Accepted 85ms 7.289 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-11-11 03:01:24
Judged By
Score
100
Total Time
152ms
Peak Memory
7.945 MiB