Baekjoon

Baekjoon 13417번 카드 문자열

ppwag 2020. 9. 27. 23:31

문제

https://www.acmicpc.net/problem/13417

걸린 시간

00 : 18 : 20

풀이

C++

#include <bits/stdc++.h>
#define INF 1e9
typedef long long ll;
using namespace std;

vector<char> card;
deque<char> dq;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin >> tc;
    while(tc--){
        int n;
        cin >> n;
        card.resize(n);
        for(auto& i : card) cin >> i;
        dq.push_back(card[0]);
        for(int i = 1; i < n; i++)
            if(dq.front() >= card[i])
                dq.push_front(card[i]);
            else
                dq.push_back(card[i]);
        while(!dq.empty()){
            cout << dq.front();
            dq.pop_front();
        }
        cout << "\n";
    }
    return 0;
}

댓글