Accepted
Code
#include<bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
deque<char> front(s.begin(), s.end());
deque<char> back;
int q;
cin >> q;
bool reversed = false;
while (q--) {
int queryType;
cin >> queryType;
if (queryType == 1) {
reversed = !reversed;
}
else {
int d;
char C;
cin >> d >> C;
if (reversed) {
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 (reversed) {
for (auto it = back.rbegin(); it != back.rend(); ++it) {
cout << *it;
}
for (auto it = front.rbegin(); it != front.rend(); ++it) {
cout << *it;
}
} else {
for (auto ch : front) {
cout << ch;
}
for (auto ch : back) {
cout << ch;
}
}
cout << endl;
}
return 0;
}
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:08:05
- Judged At
- 2024-11-11 03:01:35
- Judged By
- Score
- 100
- Total Time
- 846ms
- Peak Memory
- 9.246 MiB