프로그래밍 공부/백준 (C++)
[C++ / 백준 17413번] 단어 뒤집기 2
Rocketbabydolls
2024. 10. 14. 16:53
#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;
}