-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5430.cpp
111 lines (106 loc) · 1.46 KB
/
5430.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 5430. AC
// 2019.05.21
// 덱
#include<iostream>
#include<queue>
#include<string>
#include<sstream>
using namespace std;
int main()
{
int t;
cin >> t;
deque<int> dq;
for (int i = 0; i < t; i++)
{
dq.clear();
bool flag = true;
bool errorFlag = false;
string p;
cin >> p;
int n;
cin >> n;
string arr;
cin >> arr;
string tmp;
if (arr.size() == 2)
{
dq.clear();
}
else
{
for (int i = 1; i < arr.size(); i++)
{
if (arr[i] == ',')
{
dq.push_back(stoi(tmp));
tmp = "";
}
else if (i == arr.size() - 1)
{
dq.push_back(stoi(tmp));
}
else
{
tmp += arr[i];
}
}
}
for (int i = 0; i < p.size(); i++)
{
if (p[i] == 'R')
{
flag = !flag;
}
else
{
if (flag)
{
if (dq.size() == 0)
{
errorFlag = true;
cout << "error" << endl;
break;
}
dq.pop_front();
}
else
{
if (dq.size() == 0)
{
errorFlag = true;
cout << "error" << endl;
break;
}
dq.pop_back();
}
}
}
if (!dq.empty())
{
if (flag)
{
cout << "[";
for (int i = 0; i < dq.size() - 1; i++)
{
cout << dq[i] << ",";
}
cout << dq[dq.size() - 1] << "]" << endl;
}
else
{
cout << "[";
for (int i = dq.size()-1; i >=1; i--)
{
cout << dq[i] << ",";
}
cout << dq[0] << "]" << endl;
}
}
else if(!errorFlag)
{
cout << "[]" << endl;
}
}
return 0;
}