-
https://www.acmicpc.net/problem/1406
1406번: 에디터
첫째 줄에는 초기에 편집기에 입력되어 있는 문자열이 주어진다. 이 문자열은 길이가 N이고, 영어 소문자로만 이루어져 있으며, 길이는 100,000을 넘지 않는다. 둘째 줄에는 입력할 명령어의 개수
www.acmicpc.net
#include <list> #include <string> #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string arr; cin >> arr; list<char> edit; for (int i = 0; i < arr.size(); i++) edit.push_back(arr[i]); int M; cin >> M; list<char>::iterator cursor = edit.end(); for (int i = 0; i < M; i++) { char temp; cin >> temp; if (temp == 'L') { if (cursor != edit.begin()) cursor--; } else if (temp == 'D') { if (cursor != edit.end()) cursor++; } else if (temp == 'B') { if (cursor != edit.begin()) cursor = edit.erase(--cursor); } else if (temp == 'P') { char chr; cin >> chr; edit.insert(cursor, chr); } } for (list<char>::iterator iter = edit.begin(); iter != edit.end(); iter++) cout << *iter; return 0; } // 블로그 참고, https://iingang.github.io/posts/BOJ-1406/
'코딩 테스트 > 백준' 카테고리의 다른 글
1158 요세푸스 문제 (0) 2022.02.14 10845 큐 (0) 2022.02.12 1874 스택 수열 (0) 2022.02.10 9012 괄호 (0) 2022.02.09 9093 단어 뒤집기 (0) 2022.02.08