Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created February 28, 2016 13:19
Show Gist options
  • Save HyeonWooKim/da543f974e7b5ff0cc17 to your computer and use it in GitHub Desktop.
Save HyeonWooKim/da543f974e7b5ff0cc17 to your computer and use it in GitHub Desktop.
에디터 C++ 버전(BOJ 1406)
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
string s;
stack<char> lst,rst;
int n;
char c;
cin>>s>>n;
for(int i=0;i<s.length(); i++)
lst.push(s[i]);
for(int i=0;i<n;i++)
{
cin>>c;
if(c=='L' && !lst.empty())
{
rst.push(lst.top());
lst.pop();
}
else if(c=='D' && !rst.empty())
{
lst.push(rst.top());
rst.pop();
}
else if(c=='B' && !lst.empty())
{
lst.pop();
}
else if(c=='P')
{
cin>>c;
lst.push(c);
}
}
while(!lst.empty())
{
rst.push(lst.top());
lst.pop();
}
while(!rst.empty())
{
cout<<rst.top();
rst.pop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment