-
Notifications
You must be signed in to change notification settings - Fork 0
/
17413.cpp
46 lines (40 loc) · 960 Bytes
/
17413.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
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
string stmt;
getline(cin, stmt);
stack<string::value_type> st;
string::size_type idx = 0;
bool reverse = true;
while (idx < stmt.size()) {
string::value_type ch = stmt[idx++];
if (ch == '<') {
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << ch;
reverse = false;
} else if (ch == ' ' && reverse) {
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << ch;
} else if (ch == '>') {
cout << ch;
reverse = true;
} else if (reverse) {
st.push(ch);
} else {
cout << ch;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
return 0;
}