1406_에디터(C++)


#include <iostream>
#include<stack>
using namespace std;

int main() {
    char command;
    string N;
    int T;
    cin >> N >> T;
    stack<char> mine_right;
    stack<char> mine_left;
    for (int i = 0; i < N.length(); i++) {
        mine_left.push(N[i]);
    }
    for (int i = 0; i < T; i++) {
        cin >> command;
        if (command == 'L') {
            if (!mine_left.empty()) {
                mine_right.push(mine_left.top());
                mine_left.pop();
            }
        }
        else if (command == 'D') {
            if (!mine_right.empty()) {
                mine_left.push(mine_right.top());
                mine_right.pop();
            }
        }
        else if (command == 'B') {
            if (!mine_left.empty()) mine_left.pop();
        }
        else if (command == 'P') {
            char $;
            cin >> $;
            mine_left.push($);
        }
    }
    while (!mine_left.empty()) {
        mine_right.push(mine_left.top());
        mine_left.pop();
    }
    while (!mine_right.empty()) {
        cout<< mine_right.top();
        mine_right.pop();
    }
        
}

스택 설명 참고:
https://velog.io/@kimeunseo58/%EC%8A%A4%ED%83%9D
스택 소스코드:
https://velog.io/@kimeunseo58/10828%EC%8A%A4%ED%83%9DC

좋은 웹페이지 즐겨찾기