-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheGrandAdventure.cpp
64 lines (60 loc) · 1.65 KB
/
TheGrandAdventure.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
#include <bits/stdc++.h>
using namespace std;
int main(){
string line;
getline(cin, line);
int nCases = stoi(line);
nextJourney:
while(nCases--){
stack<char> backpack;
getline(cin, line);
stringstream ss(line);
bool good = true;
char c;
while(ss >> c){
switch(c){
case '$':
backpack.push('$');
break;
case '|':
backpack.push('|');
break;
case '*':
backpack.push('*');
break;
case 't':
if(backpack.size() == 0 || backpack.top() != '|'){
good = false;
} else {
backpack.pop();
}
break;
case 'j':
if(backpack.size() == 0 || backpack.top() != '*'){
good = false;
} else {
backpack.pop();
}
break;
case 'b':
if(backpack.size() == 0 || backpack.top() != '$'){
good = false;
} else {
backpack.pop();
}
break;
default:
break;
}
if(!good){
break;
}
}
if(!good || backpack.size() != 0){
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}