Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- c++
- Team Fortress 2
- VR
- 트리
- 누적 합
- 정렬
- 다이나믹 프로그래밍
- 스택
- 문자열
- 수학
- 백트래킹
- 우선순위 큐
- 알고리즘
- 투 포인터
- 구현
- 유니온 파인드
- 브루트포스
- 백준
- XR Interaction Toolkit
- Unreal Engine 5
- 그래프
- DFS
- 그리디 알고리즘
- 다익스트라
- BFS
- 재귀
- 유니티
- ue5
- 자료구조
- 시뮬레이션
Archives
- Today
- Total
1일1알
백준 1406번 에디터 C++ 본문
중간 삽입 삭제가 O(1)인 연결 리스트를 이용하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
list<char> lst;
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
lst.push_back(str[i]);
}
auto cursor = lst.end();
int m;
cin >> m;
for (int i = 0; i < m; i++) {
char order;
cin >> order;
if (order == 'P') {
char c;
cin >> c;
cursor = lst.insert(cursor, c);
++cursor;
}
else if (order == 'L') {
if (cursor == lst.begin()) continue;
--cursor;
}
else if (order == 'D') {
if (cursor == lst.end()) continue;
++cursor;
}
else if (order == 'B') {
if (cursor == lst.begin()) continue;
auto nextCursor = cursor;
--nextCursor;
cursor = lst.erase(nextCursor);
}
}
for (auto a : lst) {
cout << a;
}
};
'알고리즘' 카테고리의 다른 글
백준 18258번 큐 2 C++ (0) | 2022.06.06 |
---|---|
백준 1021번 회전하는 큐 C++ (0) | 2022.06.05 |
백준 10815번 숫자 카드 C++ (0) | 2022.06.03 |
백준 1158번 요세푸스 문제 C++ (0) | 2022.06.02 |
백준 10799번 쇠막대기 C++ (0) | 2022.06.01 |