Created
February 28, 2016 13:19
-
-
Save HyeonWooKim/da543f974e7b5ff0cc17 to your computer and use it in GitHub Desktop.
에디터 C++ 버전(BOJ 1406)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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