计蒜客 网页跳转

来源:互联网 发布:在线二次元av淘宝 编辑:程序博客网 时间:2024/05/16 01:35

蒜头君每天都在用一款名为“蒜厂浏览器”的软件。在这个浏览器中,一共三种操作:打开页面、回退和前进。它们的功能如下:

  • 打开页面:在地址栏中输入网址,并跳转到网址对应的页面;
  • 回退:返回到上一次访问的页面;
  • 前进:返回到上次回退前的页面,如果上一次操作是打开页面,那么将无法前进。

现在,蒜头君打开浏览器,进行了一系列操作,你需要输出他每次操作后所在页面的网址。

输入格式

第一行输入一个整数 n(0<n≤100000)n(0 < n \le 100000)n(0<n100000),表示蒜头君的操作次数。

接下来一共 nnn 行,每行首先输入一个字符串,如果是VISIT,后面接着输入一个不含有空格和换行的网址(网址长度小于 100100100),表示蒜头君在浏览器地址栏中输入的网址;如果是BACK,表示蒜头君点击了回退按钮;如果是FORWARD,表示蒜头君点击了前进按钮。

输出格式

对于每次操作,如果蒜头君能操作成功,输出蒜头君操作之后的网址,否则输出Ignore假设蒜头君输入的所有网址都是合法的

样例输入

10VISIT https://www.jisuanke.com/course/476VISIT https://www.taobao.com/BACKBACKFORWARDFORWARDBACKVISIT https://www.jisuanke.com/course/429FORWARDBACK

样例输出

https://www.jisuanke.com/course/476https://www.taobao.com/https://www.jisuanke.com/course/476Ignorehttps://www.taobao.com/Ignorehttps://www.jisuanke.com/course/476https://www.jisuanke.com/course/429Ignorehttps://www.jisuanke.com/course/476

#include #include #include using namespace std;int main() {ios::sync_with_stdio(false);   //避免超时stack s1;stack s2;int n;cin >> n;while (n--) {string str1, str2;cin >> str1;if (str1 == "VISIT") {cin >> str2;while (!s2.empty()) {//清空s2s2.pop();}s1.push(str2);cout << s1.top() << endl;}else if (str1 == "BACK") {if (s1.empty()) {cout << "Ignore" << endl;}else {s2.push(s1.top());s1.pop();if (!s1.empty()) {cout << s1.top() << endl;}else {cout << "Ignore" << endl;s1.push(s2.top());s2.pop();}}}else {if (s2.empty()) {cout << "Ignore" << endl;}else {if (!s2.empty()) {cout << s2.top() << endl;s1.push(s2.top());s2.pop();}else {cout << "Ignore" << endl;}}}}}
原创粉丝点击