forked from hackerkid/LightOJ-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1113-Dsicover-The-Web.cpp
109 lines (75 loc) · 1.17 KB
/
1113-Dsicover-The-Web.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
#include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
string choice;
int turn;
int nextturn()
{
if(choice == "VISIT") {
turn = 0;
}
if(choice == "FORWARD") {
turn = 1;
}
if(choice == "BACK") {
turn = 2;
}
}
int main()
{
ios_base::sync_with_stdio(false);
int t;
string url;
stack <string> f;
stack <string> b;
cin >> t;
for (int cs = 1; cs <= t; cs++) {
cin >> choice;
while(!b.empty()) {
b.pop();
}
while(!f.empty()) {
f.pop();
}
url = "http://www.lightoj.com/";
cout << "Case "<<cs<<":\n";
while(choice != "QUIT") {
nextturn();
switch(turn) {
//vis for back
case 0:
b.push(url);
cin >> url;
cout << url << "\n";
while(!f.empty()) {
f.pop();
}
break;
case 1:
if(f.empty()) {
cout << "Ignored\n";
}
else {
b.push(url);
url = f.top();
f.pop();
cout << url << "\n";
}
break;
case 2:
if(b.empty()) {
cout << "Ignored\n";
}
else {
f.push(url);
url = b.top();
b.pop();
cout << url << "\n";
}
break;
}
cin >> choice;
}
}
}