-
9093 단어 뒤집기코딩 테스트/백준 2022. 2. 8. 22:36
https://www.acmicpc.net/problem/9093
9093번: 단어 뒤집기
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문장이 하나 주어진다. 단어의 길이는 최대 20, 문장의 길이는 최대 1000이다. 단어와 단어 사이에는
www.acmicpc.net
#include <stack> #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; cin.ignore(); while (T--) { string temp; getline(cin, temp); temp += ' '; stack<char> chr; for (int i = 0; i < temp.size(); i++) { if (temp[i] == ' ') { while (chr.empty() == false) { cout << chr.top(); chr.pop(); } cout << temp[i]; } else chr.push(temp[i]); } } return 0; } // 블로그 참고, https://intaehwang.tistory.com/29