#include <iostream>
#include <stack>
#include <sstream>
using namespace std;
int main() {
string input;
stack <char> s;
getline (cin, input);
for(int i = 0 ; i < input.length(); i++)
{
if(input[i] == '<')
{
while(!s.empty())
{
char tmp = s.top();
s.pop();
cout << tmp;
}
while(true)
{
if (input[i] == '>')
{
cout << '>';
break;
}
cout << input[i];
i++;
}
}
else if(input[i] == ' ')
{
while(!s.empty())
{
char tmp = s.top();
s.pop();
cout << tmp;
}
cout << ' ';
continue;
}
else
s.push(input[i]);
}
while(!s.empty())
{
char tmp = s.top();
s.pop();
cout << tmp;
}
return 0;
}
'프로그래밍 공부 > 백준 (C++)' 카테고리의 다른 글
[C++/백준 17298번] 오큰수 (0) | 2024.10.24 |
---|---|
[C++/백준 10799번] 쇠막대기 (0) | 2024.10.14 |
[C++/백준 10866번] 덱 (0) | 2024.10.12 |
[C++/백준 1158번] 요세푸스 문제 (0) | 2024.10.12 |
[C++/백준 10845번] 큐 (0) | 2024.10.12 |