V
来源:互联网 发布:小智淘宝店叫什么 编辑:程序博客网 时间:2024/04/24 12:16
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. You are asked to implement this. The commands are:
1. BACK: If the backward stack is empty, the command is ignored. Otherwise, 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.
2. FORWARD: If the forward stack is empty, the command is ignored. Otherwise, push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page.
3. 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.
4. QUIT: Quit the browser.
The browser initially loads the web page at the URL 'http://www.lightoj.com/'
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains some commands. The keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 50 characters. The end of case is indicated by the QUIT command and it shouldn't be processed. Each case contains at most 100 lines.
For each case, print the case number first. For each command, print the URL of the current page (in a line) after the command is executed if the command is not ignored. Otherwise, print'Ignored'.
1
VISIT http://uva.onlinejudge.org/
VISIT http://topcoder.com/
BACK
BACK
BACK
FORWARD
VISIT http://acm.sgu.ru/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT
Case 1:
http://uva.onlinejudge.org/
http://topcoder.com/
http://uva.onlinejudge.org/
http://www.lightoj.com/
Ignored
http://uva.onlinejudge.org/
http://acm.sgu.ru/
http://uva.onlinejudge.org/
http://www.lightoj.com/
http://uva.onlinejudge.org/
http://acm.sgu.ru/
Ignored
emmmm是一道简单的模拟水题然后需要注意的坑点就是 要记得!!!结束的时候要把x y清空
还有就是此刻页面的状态d要记得记得记得恢复成题目的样子就是这个样子没了
还有中秋啊 中秋快乐
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#include<string>#include<iostream>using namespace std;int main(){stack<string>x,y;//x表示后退 y表示前进string a,b,d;d="http://www.lightoj.com/";//表示当前页这是不断被更新的int t;scanf("%d",&t);for(int o=1;o<=t;o++){ while(x.empty()==0) x.pop(); while(y.empty()==0) y.pop(); printf("Case %d:\n",o); d="http://www.lightoj.com/"; while(1) { cin>>a; if(a[0]=='Q') break;//这边是没有问题的 else if(a[0]=='V') { cin>>b; cout<<b<<endl; //输出当前的状态 x.push(d);//把b放在后面 d=b;//更新状态 d表示的是当前的状态 while(y.empty()==0) y.pop(); }else if(a[0]=='F') { if(y.empty()==1) puts("Ignored"); else { x.push(d); string h=y.top(); y.pop(); d=h; cout<<h<<endl; } }else if(a[0]=='B') { if(x.empty()==1) puts("Ignored"); else { y.push(d); string h=x.top(); x.pop(); d=h; cout<<h<<endl; } } }}return 0;}
- V
- v
- v
- v
- v
- v
- V
- V
- V
- V
- V
- V
- v
- V
- V
- V
- v
- V
- JSP技术-02-内置对象/作用域/EL表达式/JSTL标签库
- 【mybatis】【idea】【maven】Invalid bound statement (not found)的解决
- spring boot项目实战:分布式锁
- 大数据的加法运算Java代码实现
- win10配置Java环境变量.
- V
- python27的Windows下环境搭建
- 大数的减法运算Java代码实现
- 计算机组成原理提要(一)--计算机基本组成与主要技术指标
- HDU-1042(java 大数)
- ElGamal实现加密算法
- 接口初识
- 大数乘法计算Java代码实现
- 1.在屏幕上输出以下图案: // * // *** // ***** // ******* // ********* // *********** //*********