-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5430.cpp
More file actions
65 lines (63 loc) · 1.42 KB
/
5430.cpp
File metadata and controls
65 lines (63 loc) · 1.42 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <string>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int T,n,num;
char op;
string p;
deque<int> deq;
cin>>T;
string res;
for(int t=0;t<T;t++){
cin>>p>>n;
deq.clear();
res.clear();
bool d=false;
cin>>op;
for(int i=0;i<n;i++){
cin>>num>>op;
deq.push_back(num);
}
if(n==0) cin>>op;
for(char c:p){
if(c=='R'){
d=!d;
}else if(c=='D'){
if(!deq.empty()){
if(d){
deq.pop_back();
}else{
deq.pop_front();
}
}else{
res="error";
break;
}
}
}
if(res.empty()){
res+='[';
if(d){
deque<int>::reverse_iterator rit=deq.rbegin();
for(;rit!=deq.rend();rit++){
res+=to_string(*rit)+',';
}
}else{
for(int i:deq){
res+=to_string(i)+',';
}
}
if(!deq.empty())
res.pop_back();
res+=']';
}
cout<<res<<'\n';
}
return 0;
}