Accepted
Code
#include <algorithm>
#include<bits/stdc++.h>
#include <functional>
using namespace std;
#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vii;
int main () {
FASTIO
int t;
cin>>t;
while (t--) {
string s;
cin>>s;
int q;
cin>>q;
int cnt = 0;
string bg;
while (q--) {
int op;
cin>>op;
if (op == 1) {
cnt++;
} else {
int d;
char c;
cin>>d>>c;
if (d == 1) {
if (cnt % 2 == 0) {
// s = c + s;
bg.push_back(c);
} else {
s.push_back (c);
}
} else {
if (cnt % 2 == 0) {
s.push_back (c);
} else {
// s = c + s;
bg.push_back(c);
}
}
}
}
reverse(bg.begin(), bg.end());
// cout<<bg<<nl;
s = bg + s;
// cout<<s<<nl;
if (cnt & 1) {
reverse (s.begin(), s.end());
}
cout<<s<<nl;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1088 Mr. Heart's String Challenge
- Contest
- Brain Booster #5
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-09-05 16:11:35
- Judged At
- 2024-11-11 03:01:27
- Judged By
- Score
- 100
- Total Time
- 137ms
- Peak Memory
- 7.891 MiB