백준 5397 키로거

JunSeok·2023년 1월 9일
0

백준

목록 보기
4/40

풀이

연결리스트 이용하여 별 어려움 없이 해결했다.

#include <bits/stdc++.h>
using namespace std;

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N; // the number of test case
    cin >> N;
    while(N--) {
        string s;
        list<char> L;
        cin >> s;
        auto cur = L.begin();
        for(auto c : s) {
            if(c == '<') {
                if(cur != L.begin()) cur--;
            }
            else if(c == '>') {
                if(cur != L.end()) cur++;
            }
            else if(c == '-') {
                if(cur != L.begin()) {
                    cur--;
                    cur = L.erase(cur);
                }
            }
            else {
                L.insert(cur, c);
            }
        }
        for(auto i : L) cout << i;
        cout << '\n';
    }
}
profile
최선을 다한다는 것은 할 수 있는 한 가장 핵심을 향한다는 것

0개의 댓글