/*
实现浏览器的页面前后访问机制。有四种命令:
1、BACK;
2、FORWARD;
3、VISIT:访问新的页面;
4、QUIT:退出浏览器。
请参考实际的浏览器按钮的功能。
假设浏览器打开时,显示的页面是:http://www.acm.org/
一系列命令:以BACK、FORWARD、VISIT或QUIT开头。
如果是VISIT,后面要跟URL,长度不超过70,且不含空格。最后总是以QUIT结尾。
对于每一个命令(除了QUIT),输出浏览页面的URL,如果命令被忽略,输出:Ignored。
input:
VISIT http://acm.ashland.edu/
VISIT http://asm.baylor.edu/acmipc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT
output:
http://acm.ashland.edu/
http://asm.baylor.edu/acmipc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored
*/
#include<iostream>
#include<string> //为了使用 string 这个数据类型
using namespace std;
const int N = 100;
string str,back[N],front[N],result[N]; // 用两个string[] 分别对前面和后面进行保存,将要打印的保存在result
string now = "http://www.acm.org/"; // now用于标定 当前的状态
int main()
{
int i=0;
cin>>str;
int back_count = -1,front_count = -1;
int index = 0;
while(1)
{
//本题核心是对当前,以前,未来状态的转换
if("QUIT" == str)
{
break;
}
if("VISIT" == str)
{
front_count = -1;
back_count ++;
back[back_count] = now;
// 因为题目给定的输入在VISIT 后的url会有 一个空格,所以只会输入 VISIT,再次才会输入URL
cin>>now;
result[index] = now;
index ++;
}
if("FORWARD" == str)
{
if(front_count>-1)
{
back_count++;
back[back_count] = now;
now = front[front_count];
front_count --;
result[index] = now;
index++;
}
else
{
result[index] = "Ignored";
index++;
}
}
if("BACK" == str)
{
if(back_count>-1)
{
front_count ++;
front[front_count] = now;
now = back[back_count];
back_count --;
result[index] = now;
index ++;
}
else
{
result[index] = "Ignored";
index++;
}
}
cin>>str;
}
for(int i=0;i<index;i++)
{
cout<<result[i]<<endl;
}
}
实现浏览器的页面前后访问机制。有四种命令:
1、BACK;
2、FORWARD;
3、VISIT:访问新的页面;
4、QUIT:退出浏览器。
请参考实际的浏览器按钮的功能。
假设浏览器打开时,显示的页面是:http://www.acm.org/
一系列命令:以BACK、FORWARD、VISIT或QUIT开头。
如果是VISIT,后面要跟URL,长度不超过70,且不含空格。最后总是以QUIT结尾。
对于每一个命令(除了QUIT),输出浏览页面的URL,如果命令被忽略,输出:Ignored。
input:
VISIT http://acm.ashland.edu/
VISIT http://asm.baylor.edu/acmipc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT
output:
http://acm.ashland.edu/
http://asm.baylor.edu/acmipc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored
*/
#include<iostream>
#include<string> //为了使用 string 这个数据类型
using namespace std;
const int N = 100;
string str,back[N],front[N],result[N]; // 用两个string[] 分别对前面和后面进行保存,将要打印的保存在result
string now = "http://www.acm.org/"; // now用于标定 当前的状态
int main()
{
int i=0;
cin>>str;
int back_count = -1,front_count = -1;
int index = 0;
while(1)
{
//本题核心是对当前,以前,未来状态的转换
if("QUIT" == str)
{
break;
}
if("VISIT" == str)
{
front_count = -1;
back_count ++;
back[back_count] = now;
// 因为题目给定的输入在VISIT 后的url会有 一个空格,所以只会输入 VISIT,再次才会输入URL
cin>>now;
result[index] = now;
index ++;
}
if("FORWARD" == str)
{
if(front_count>-1)
{
back_count++;
back[back_count] = now;
now = front[front_count];
front_count --;
result[index] = now;
index++;
}
else
{
result[index] = "Ignored";
index++;
}
}
if("BACK" == str)
{
if(back_count>-1)
{
front_count ++;
front[front_count] = now;
now = back[back_count];
back_count --;
result[index] = now;
index ++;
}
else
{
result[index] = "Ignored";
index++;
}
}
cin>>str;
}
for(int i=0;i<index;i++)
{
cout<<result[i]<<endl;
}
}