-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ-1028-Web Navigation-easy.cpp
66 lines (63 loc) · 1.06 KB
/
POJ-1028-Web Navigation-easy.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
/**
*POJ-1028-Web Navigation
*xuchen
*2015-11-20 19:46:10
**/
#include "stdio.h"
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
string s;
stack<string> backwordStack;
stack<string> forwardStack;
int main()
{
char command[10];
string cur = "http://www.acm.org/";
string url;
while(scanf("%s", command) && command[0]!='Q')
{
switch(command[0]){
case 'B':
if(backwordStack.empty())
{
printf("Ignored\n");
}
else
{
forwardStack.push(cur);
cur = backwordStack.top();
backwordStack.pop();
cout<<cur<<endl;
}
break;
case 'F':
if(forwardStack.empty())
{
printf("Ignored\n");
}
else
{
backwordStack.push(cur);
cur = forwardStack.top();
forwardStack.pop();
cout<<cur<<endl;
}
break;
case 'V':
cin>>url;
backwordStack.push(cur);
cur = url;
while(!forwardStack.empty())
forwardStack.pop();
cout<<cur<<endl;
break;
}
}
return 0;
}