BOJ 1406 c++ 에디터

Algorithm / / 2020. 7. 27. 15:45

BOJ 1406 C++ 에디터

백준 1406

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

int ea;
list<char> editor;

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string line;
    cin >> line;
    for (int i = 0; line[i]; i++) {
        editor.push_back(line[i]);
    }
    auto t = editor.end();

    cin >> ea;
    while (ea--) {
        char c;
        cin >> c;
        if (c == 'L') {
            if (t != editor.begin()) {
                t--;
            }
        } else if (c == 'D') {
            if (t != editor.end()) {
                t++;
            }
        } else if (c == 'B') {
            if (t != editor.begin()) {
                t--;
                t = editor.erase(t);
            }
        } else if (c == 'P') {
            char content;
            cin >> content;
            editor.insert(t, content);
        }
    }
    for (auto e : editor) {
        cout << e;
    }
}

'Algorithm' 카테고리의 다른 글

BOJ 2577 숫자의 개수 c++  (0) 2020.08.14
BOJ 10807 개수 세기 c++  (0) 2020.08.14
BOJ 1260 c++ BFS와 DFS  (0) 2020.07.22
BOJ 11724 c++ 연결 요소의 개수  (0) 2020.07.22
C++ 이진 탐색 STL binary_search, upper_bound, lower_bound  (0) 2020.07.18
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기
// custom