网页浏览历史

匿名 (未验证) 提交于 2019-12-03 00:39:02

题目描述

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

输入描述:

输入包含多组数据,每组数据第一行包含一个正整数n1n100)。

紧接着有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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!