-
Notifications
You must be signed in to change notification settings - Fork 96
/
[02]_3.cpp
53 lines (46 loc) · 817 Bytes
/
[02]_3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
int tc;
int main() {
cin >> tc;
while (tc--) {
string s;
cin >> s;
stack<char> left;
stack<char> right;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '-') {
if (!left.empty()) left.pop();
}
else if (s[i] == '<') {
if (!left.empty()) {
right.push(left.top());
left.pop();
}
}
else if (s[i] == '>') {
if (!right.empty()) {
left.push(right.top());
right.pop();
}
}
else {
left.push(s[i]);
}
}
vector<char> result;
while (!right.empty()) {
left.push(right.top());
right.pop();
}
while (!left.empty()) {
result.push_back(left.top());
left.pop();
}
reverse(result.begin(), result.end());
for (auto x: result) {
cout << x;
}
cout << '\n';
}
}