【题意简述】:题目的大概意思,就是模仿浏览器的功能,实现访问(VISITE)URL,前进(FORWORD),后退(BACK)
这些功能!
【思路】:可以模拟栈的用法!后进先出,实现这一功能。
实现功能,详见代码!!
/*0ms,164KB*/
#include<iostream>
#include<string>
using namespace std;
string stack[101];
int main()
{
int top;
int Max1;
int n;
string op;
// cin>>n;
//while(n--){
Max1 = 0;
top = 0;
stack[top] = "http://www.acm.org/";
while (cin >> op, op[0] != 'Q')
{
if (op[0] == 'V')
{
string web;
cin >> web;
stack[++top] = web;
cout << web << endl;
Max1 = top;
}
else if (op[0] == 'B')
{
if (top != 0)
cout << stack[--top] << endl;
else
cout << "Ignored" << endl;
}
else//'F'
{
if (top < Max1)
cout << stack[++top] << endl;
else
cout << "Ignored" << endl;
}
// }
//cout<<endl;
}
return 0;
}