fork(3) download
  1. // ConsoleApplication1.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
  2. //
  3.  
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(false);
  14.  
  15. int N;
  16. char ch;
  17. char order;
  18. char cs;
  19. char num;
  20. stack<char> left, right;
  21.  
  22. while ((ch = getchar()) != '\n') {
  23. left.push(ch);
  24. }
  25.  
  26. cin >> N;
  27.  
  28. for (int i = 0; i < N; i++) {
  29. cin >> order;
  30. if (order == 'L') {
  31. if (!(left.empty())) {
  32. cs = left.top();
  33. right.push(cs);
  34. left.pop();
  35. }
  36. }
  37. if (order == 'D') {
  38. if (!(right.empty())) {
  39. cs = right.top();
  40. left.push(cs);
  41. right.pop();
  42. }
  43. }
  44. if (order == 'B') {
  45. if (!(left.empty())) {
  46. left.pop();
  47. }
  48. }
  49. if (order == 'P') {
  50. cin >> num;
  51. left.push(num);
  52. }
  53. }
  54.  
  55. while (!(left.empty())) {
  56. cs = left.top();
  57. right.push(cs);
  58. left.pop();
  59. }
  60.  
  61. while (!(right.empty())) {
  62. cs = right.top();
  63. cout << cs;
  64. right.pop();
  65. }
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0s 4356KB
stdin
abcd
3
P x
L
P y
stdout
abcd