ㅅwww.acmicpc.net/problem/1406

 

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;
}
Posted by 명문코딩컴퓨터
,