자라는 개발자/문제풀이

백준 c++ 5397 키로거

자란다 2022. 1. 14. 22:28
728x90
반응형

5397 키로거

문제 풀이

#include <bits/stdc++.h>
#include <ctype.h>

using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main(void)
{
    fast_io();
    int t;
    cin >> t;
    while (t--)
    {
        string str;
        list<char> l;
        cin >> str;
        list<char>::iterator iter = l.end();
        for (int i = 0; i < str.length(); i++)
        {
            if (isdigit(str[i]) || isalpha(str[i]))
                l.insert(iter, str[i]);
            else if (str[i] == '<' && iter != l.begin())
                iter--;
            else if (str[i] == '>' && iter != l.end())
                iter++;
            else if (str[i] == '-' && iter != l.begin())
                iter = l.erase(--iter);
        }
        for (char c : l)
            cout << c;
        cout << "\n";
    }
}

iter의 전치 후치 연산에따라 값이바뀌고 맨처음에 iter에 end 값으로 초기화 해줘야한다.

728x90
반응형