分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

网页浏览历史

发布时间:2023-09-06 02:02责任编辑:彭小芳关键词:暂无标签

题目描述

标准的网页浏览器都提供一个功能:保留最近浏览过页面的历史记录。通过后退或向前按钮就能在历史记录之间跳转。
?现在,请你模拟这个功能,接收如下三条指令:
?1. BACK:回退功能,即回退到上一个访问的页面;
?2. FORWARD:使用BACK返回上一页之后,可以使用FORWARD回到下一页;
?3. VISIT url:访问指定url的页面,并且所有FORWARD的页面都被清空。

输入描述:

输入包含多组数据,每组数据第一行包含一个正整数n(1≤n≤100)。

紧接着有n行,每一行包含一条指令。其中url是不包含空格、长度不超过100的非空字符串。

输出描述:

对应每组数据,为每条指令输出当前页面的URL。

如果当前指令无效(例如没有上一页时执行BACK指令、或没有下一页时执行FORWARD指令),则输出一行“ignore”。

每组数据之后输出一个空行作为分隔。



先来我的代码:
#include<iostream>#include<stack>#include<stdio.h>using namespace std;int find_order(string t){ ???string a="VISIT"; ???string b="BACK"; ???string c="FORWARD"; ???if(t==a) ???????return 1; ???else if(t==b) ???????return 2; ???else ???????return 3;}int main(){ ???stack<string> a; ???stack<string> b; ???string t1,t2; ???int n; ???while(scanf("%d",&n)!=EOF) ???{ ???????for(int i=0; i<n; i++) ???????{ ???????????cin>>t1; ???????????int c=find_order(t1); ???????????if(c==1) ???????????{ ???????????????cin>>t2; ???????????????a.push(t2); ???????????????cout<<t2<<endl; ???????????????while( !b.empty() ) ???????????????????b.pop(); ???????????} ???????????else if(c==2) ???????????{ ???????????????if(a.size()<2) ???????????????{ ???????????????????cout<<"ignore\n"; ???????????????} ???????????????else ???????????????{ ???????????????????b.push(a.top()); ???????????????????a.pop(); ???????????????????cout<<a.top()<<endl; ???????????????} ???????????} ???????????else ???????????{ ???????????????if(b.empty()) ???????????????{ ???????????????????cout<<"ignore\n"; ???????????????} ???????????????else ???????????????{ ???????????????????a.push(b.top()); ???????????????????cout<<b.top()<<endl; ???????????????????b.pop(); ???????????????} ???????????} ???????} ???????cout<<endl; ???????while( !a.empty() ) ???????????a.pop(); ???????while( !b.empty() ) ???????????b.pop(); ???} ???return 0;}

我就是随笔一下,以便以后回忆,如果有人想做一下  click here

网页浏览历史

原文地址:https://www.cnblogs.com/luojianyi/p/9266614.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved