본문 바로가기
PS/BOJ

[백준] 5397. 키로거(c++)

by backend 개발자 지망생 2025. 1. 26.

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

처음부터 연결리스트를 쌓아가는 문제였고, 커서를 이용하는 것을 알 수 있었다.

 


#include<iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <list>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        list<char> L;
        string s;
        auto p = L.begin();

        cin >> s;
        for (auto c: s) {
            if (c == '<') {
                if (p != L.begin())
                    p--;
            } else if (c == '>') {
                if (p != L.end())
                    p++;
            } else if (c == '-') {
                if (p != L.begin()) {
                    p--;
                    p = L.erase(p);
                }
            } else
                L.insert(p, c);
        }
        for (auto c: L)
            cout << c;
        cout << '\n';
    }
    return 0;
}

'PS > BOJ' 카테고리의 다른 글

[백준] 10828. 스택(c++)  (0) 2025.01.26
[백준] 1158. 요세푸스 문제(c++)  (0) 2025.01.26
[백준] 1406. 에디터(c++)  (0) 2025.01.26
[백준] 1919. 애너그램 만들기(c++)  (0) 2025.01.21
[백준] 11328. Strfry(c++)  (0) 2025.01.19