입력받은 단어를 뒤집어서 보여주면 된다.
하지만 태그일때는 뒤집지 않고 그대로 보여주라고 한다.
즉 태그일때와 아닐때만 구별해서 입력해주면 된다.
태그면 입력받은대로 입력 아니면 역순
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <math.h>
#include <string>
#include <stack>
#define INF 999999999
using namespace std;
int dx[8] = { 1, 0, -1, 0,-1,-1,1,1 };
int dy[8] = { 0, 1, 0, -1,-1,1,-1,1 };
int cnt;
int n, m, t, w;
int dp[300001];
int days[16];
int maxs[16];
//vector<pair<int, int>> node[300001];
vector<int> node[300001];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
int main() {
string s;
getline(cin,s);
stack<char> st;
string temp;
bool tag = false;
for (int i = 0, len = s.length(); i < len; i++) {
if (s[i] == '<') {
tag = true;
while (!st.empty()) {
temp += st.top();
st.pop();
}
temp.push_back(s[i]);
}
else if (s[i] == '>') {
temp.push_back(s[i]);
tag = false;
}
else if (tag) {
temp.push_back(s[i]);
}
else {
if (s[i] == ' ') {
while (!st.empty()) {
temp += st.top();
st.pop();
}
temp.push_back(' ');
}
else {
st.push(s[i]);
}
}
}
while (!st.empty()) {
temp += st.top();
st.pop();
}
cout << temp << endl;
return 0;
}