9093번: 단어 뒤집기
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문장이 하나 주어진다. 단어의 길이는 최대 20, 문장의 길이는 최대 1000이다. 단어와 단어 사이에는
www.acmicpc.net
#include <iostream>
#include <string>
#include <stack>
int main() {
using namespace std; ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t; cin >> t; cin.ignore();
while (t--) {
string str;
getline(cin, str);
str += "\n";
stack<char> s;
for (char ch : str) {
if (ch == ' ' || ch == '\n') {
while (!s.empty())
{
cout << s.top(); s.pop();
}
cout << ch;
}
else {
s.push(ch);
}
}
}
return 0;
}
'Problem set' 카테고리의 다른 글
[백준] 9613: GCD 합 (0) | 2020.12.29 |
---|---|
[백준] 9095: 1, 2, 3 더하기 (0) | 2020.12.29 |
[백준] 9012: 괄호 (0) | 2020.12.29 |
[백준] 8958: OX퀴즈 (0) | 2020.12.29 |
[백준] 6588: 골드바흐의 추측 (0) | 2020.12.29 |