joj1035
2011-09-03 20:28
302 查看
1035:
Web Navigator
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 1519 | 448 | Standard |
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 anytime. 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 QUITcommand.
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;
}
相关文章推荐
- CJOJ 2022 【一本通】简单的背包问题(搜索)
- 【CJOJ P1096】最佳老农
- 51nod 1035 最长的循环节
- HPU-1035-矩阵乘法
- 1035. Password (20)
- hdu1035
- POJ 1035 Spell checker 【字符串暴力查找】
- Python实现Pat 1035. Password (20)
- 1035. Password (20)
- POJ 1035
- JOJ 1003 Channel Allocation
- JOJ 1903 1129 1157 1278
- JOJ 1064: Caeser Comes Back 解题报告
- joj 1197: Sum It Up
- POJ_1035_Trie
- joj 2558 Ocean Currents 特别的广搜
- joj 1387 CD
- joj1349 Oil Deposits
- joj 1857 Catenyms
- joj 2223: A Bug's Life (ws版的并查集)