您的位置:首页 > 其它

joj1035

2011-09-03 20:28 302 查看




1035:
Web Navigator

ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE

3s8192K1519448Standard
Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem,
you are asked to implement this.

The following commands need to be supported:

BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.

VISIT <url>: Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.

QUIT: Quit the browser.

Assume that the browser initially loads the web page at the URL http://www.acm.org/


This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.


Input

Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any
time. The end of input is indicated by the QUIT command.


Output

For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its own line. No output is produced for the QUIT
command.


Sample Input

1

VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/ BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT


Sample Output

http://acm.ashland.edu/ http://acm.baylor.edu/acmicpc/ 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


Submit / Problem List / Status / Discuss

Problem Set with Online Judge System Version 3.12

Jilin University

Developed by skywind, SIYEE

/*这不是一个难题,但是纠结了我两个小时

这个题目的叙述有问题没有给出当如果keywords是

FORWARD的时候怎么处理。。应该是将当前字符放入到

forward栈中,并且这个题要注意多组输入时候怎么解决*/

#include<stack>

#include<iostream>

#include<string>

#include<cstdio>

using namespace std;

stack<string>back_ward;

stack<string>for_ward;

int main()

{

//freopen("in.txt","r",stdin);

string keywords;

int N;

cin>>N;

getchar();

bool temp=false;

while((--N)>=0)

{

if(temp)cout<<endl;

temp=true;

string str="http://www.acm.org/";

while(!back_ward.empty())back_ward.pop();

while(!for_ward.empty())for_ward.pop();

while(cin>>keywords)

{

//cout<<keywords<<" "<<str<<endl;

if(keywords=="QUIT")break;

else if(keywords=="BACK")

{

if(back_ward.empty())

cout<<"Ignored"<<endl;

else

{

for_ward.push(str);

str=back_ward.top();

back_ward.pop();

cout<<str<<endl;

}

}

else if(keywords=="VISIT")

{

back_ward.push(str);

while(!for_ward.empty())

for_ward.pop();

cin>>str;

cout<<str<<endl;

}

else

{

if(for_ward.empty())

cout<<"Ignored"<<endl;

else

{

back_ward.push(str);

str=for_ward.top();

for_ward.pop();

cout<<str<<endl;

}

}

}

getchar();

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: