/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 107ms 3.371 MiB
#4 Accepted 25ms 8.168 MiB
#5 Accepted 2ms 532.0 KiB
#6 Accepted 121ms 2.73 MiB
#7 Accepted 112ms 2.484 MiB
#8 Accepted 22ms 1.367 MiB
#9 Accepted 47ms 8.844 MiB
#10 Accepted 67ms 7.738 MiB
#11 Accepted 26ms 3.945 MiB
#12 Accepted 32ms 8.277 MiB

Code

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
# define double long double
const int N = 2e5 + 2, MOD = 1e9 + 7;
#define deb(x) cout<<#x<<"="<<x<<endl;
#define F first
#define S second

void solve() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool f = false;
    string add_end;
    string add_beg;
    while (q--) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            f ^= 1;
        } else {
            int i;
            char c;
            cin >> i >> c;
            if (f) {
                if (i == 1)i = 2;
                else i = 1;
            }
            if (i == 1) {
                add_beg.push_back(c);
            } else {
                add_end.push_back(c);
            }
        }
    }
    reverse(add_beg.begin(), add_beg.end());
    string ans = add_beg + s + add_end;
    if (f)std::reverse(ans.begin(), ans.end());
    cout << ans;

}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
//        cout << "Case " << i + 1 << ": ";
        solve();
        cout << "\n";
    }
}

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 15:40:13
Judged At
2024-09-05 15:40:13
Judged By
Score
100
Total Time
121ms
Peak Memory
8.844 MiB