https://www.acmicpc.net/problem/9093
한 문장을 기준으로 단어를 뒤집어야 하기에 한 문장씩 입력받을 수 있어야 합니다.
#include <iostream>
#include <stack>
using namespace std;
int N;
stack<char> st;
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
cin.ignore();
while (N--)
{
string str;
getline(cin, str);
for (char c : str)
{
if (c == ' ')
{
while (!st.empty())
{
cout << st.top();
st.pop();
}
cout << c;
}
else
{
st.push(c);
}
}
while (!st.empty())
{
cout << st.top();
st.pop();
}
cout << "\n";
}
return 0;
}
getline으로 한 문장을 입력받고 단어를 구분하여 뒤집어 주면 됩니다.