1406번: 에디터
첫째 줄에는 초기에 편집기에 입력되어 있는 문자열이 주어진다. 이 문자열은 길이가 N이고, 영어 소문자로만 이루어져 있으며, 길이는 100,000을 넘지 않는다. 둘째 줄에는 입력할 명령어의 개수
www.acmicpc.net
[ 백준 406번 에디터 소스 코드 ]
#include <cstdio>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
int i,j,m,k,z=0;
char s[610000],n,o,b[610000];
scanf("%s\n", s);
scanf("%d", &m);
k = strlen(s);
stack<char> st_L;
stack<char> st_R;
for(i=0;i<k;i++)
{
st_L.push(s[i]);
}
for(i=0;i<m;i++)
{
scanf(" %c", &n);
if( n=='L' && !st_L.empty() )
{
st_R.push(st_L.top());
st_L.pop();
}
else if( n=='D' && !st_R.empty() )
{
st_L.push(st_R.top());
st_R.pop();
}
else if( n=='B' && !st_L.empty() )
{
st_L.pop();
}
else if( n=='P' )
{
scanf(" %c", &o);
st_L.push(o);
}
}
while( !st_L.empty() )
{
b[z] = st_L.top();
z++;
st_L.pop();
}
for(i=z-1;i>=0;i--)
{
printf("%c", b[i]);
}
while ( !st_R.empty() )
{
printf("%c", st_R.top());
st_R.pop();
}
return 0;
}
'백준 문제풀이' 카테고리의 다른 글
백준 1181번 단어 정렬 소스 코드 (0) | 2021.07.02 |
---|---|
백준 2617번 - 구슬찾기 소스 코드 (0) | 2021.06.04 |
백준 2458번 - 키순서 소스 코드 (0) | 2021.05.02 |
백준 2461번 - 대표선수 소스코드 (0) | 2021.05.02 |
백준 2456번 - 나는 학급회장이다 (0) | 2021.05.01 |