Algorithm

[백준] 9093번. 단어 뒤집기

스테디음 2024. 10. 5. 13:12
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int T;
    cin >> T;
    cin.ignore();
    
    string str;
    vector<char> answer;
    for(int i=0; i<T; i++) {
        getline(cin, str);

        for(char s : str) {
            if (s == ' ') {
                while(answer.size()>0) {
                    cout << answer.back();
                    answer.pop_back();
                }
                cout << " ";
            } else {
                answer.push_back(s);
            }
        }

        while(answer.size()>0) {
            cout << answer.back();
            answer.pop_back();
        }
        
        str.clear();
        cout << endl;
    }
}

'Algorithm' 카테고리의 다른 글

[백준] 9012번. 괄호  (0) 2024.10.05
[백준] 1158번. 요세푸스 문제  (0) 2024.10.03
[백준] 1546번. 평균  (0) 2024.10.03