[백준] 5397번

Jeanine·2022년 3월 4일
0

baekjoon

목록 보기
4/120
post-thumbnail
post-custom-banner

💻 C++ 기반

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

#include <iostream>
#include <string>
#include <list>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int num;
    cin >> num;

    while (num--)
    {
        string input;
        cin >> input;

        list<char> L;
        list<char>::iterator cursor = L.begin();

        for (int i = 0; i < input.length(); i++)
        {
            if (input[i] == '<')
            {
                if (cursor != L.begin())
                {
                    cursor--;
                }
            }
            else if (input[i] == '>')
            {
                if (cursor != L.end())
                {
                    cursor++;
                }
            }
            else if (input[i] == '-')
            {
                if (cursor != L.begin())
                {
                    cursor = L.erase(--cursor);
                }
            }
            else
            {
                L.insert(cursor, input[i]);
            }
        }
        for (list<char>::iterator c = L.begin(); c != L.end(); c++)
        {
            cout << *c;
        }
        cout << '\n';
    }
}
profile
Grow up everyday
post-custom-banner

0개의 댓글