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
- 그리디
- 시뮬레이션
- 빠른 입출력
- 우선순위 큐
- BFS
- 완전 탐색
- 링크드리스트
- 중복 순열
- 큐
- MST
- dfs
- 스택
- 분할 정복
- 세그먼트 트리
- 순열
- 클래스
- lis
- 크루스칼
- DP
- Knapsack
- 문자열
- 비트마스크
- SSAFY
- 이분 탐색
- 조합
- 메모리풀
- 피보나치 수
- BeautifulSoup
- 백트래킹
- 재귀
Archives
- Today
- Total
작심 24/7
[백준] 1406번 에디터 본문
1406번: 에디터
문제 한 줄로 된 간단한 에디터를 구현하려고 한다. 이 편집기는 영어 소문자만을 기록할 수 있는 편집기로, 최대 600,000글자까지 입력할 수 있다. 이 편집기에는 '커서'라는 것이 있는데, 커서는
www.acmicpc.net
5397번 키로거 문제와 같다.
커서를 기준으로 스택을 두 개 만든 뒤
L -> res가 비어있지 않으면 res의 top을 temp에 push
D -> temp가 비어있지 않으면 temp의 top을 res에 push
B -> res가 비어있지 않으면 pop
P 문자 -> res에 문자 push
명령어에 따라 이렇게 구현해주면 된다.
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string N;
int M;
cin >> N >> M;
stack <char> res, temp;
for (int i = 0; i < N.size(); i++) res.push(N[i]);
string order;
char ch;
for (int m = 0; m < M; m++) {
cin >> order;
if (order == "P") {
cin >> ch;
res.push(ch);
}
else if (order == "L") {
if (!res.empty()) {
temp.push(res.top());
res.pop();
}
}
else if (order == "D") {
if (!temp.empty()) {
res.push(temp.top());
temp.pop();
}
}
else {
if (!res.empty()) res.pop();
}
}
while (!temp.empty()) {
res.push(temp.top());
temp.pop();
}
string result;
while (!res.empty()) {
result += res.top();
res.pop();
}
reverse(result.begin(), result.end());
cout << result;
return 0;
}
'백준' 카테고리의 다른 글
[백준] 2309번 일곱 난쟁이 (0) | 2020.06.07 |
---|---|
[백준] 1912번 연속합 (0) | 2020.06.07 |
[백준] 5076번 Web Pages (0) | 2020.06.05 |
[백준] 2841번 외계인의 기타 연주 (0) | 2020.06.05 |
[백준] 2304번 창고 다각형 (4) | 2020.06.05 |
Comments