网上冲浪
时间限制1000MS内存限制256MB代码长度限制16KB
通过率20.13%
The__Flash 非常喜欢在互联网上冲浪,在各个网页上浏览信息。但她有个奇特的癖好,那就是她只在浏览器默认标签页的地址栏上键入新网页地址,通过后退按钮访问上一个网页,前进按钮访问下一个网页,绝对不会新开第二个标签页。
智子被派来监视 The__Flash的一举一动,尤其是在浏览器中的操作。1379号监听员收到了智子发来的的消息,发现 The__Flash 在浏览器中的操作可以分为 33 类,分别是:
back:通过后退按钮访问上一个网页,若上一个网页不存在则停留在当前网页。
forward:通过前进按钮访问下一个网页,若下一个网页不存在则停留在当前网页。
visit urlurl:键入新网页地址 urlurl 并访问。
The__Flash 的初始网页是 “https://www.baidu.com/”(不包括引号),此时上一个网页和下一个网页都不存在。而你作为同志,需要帮助1379号监听员复原 The__Flash 每次操作后访问的页面。
输入描述
第一行输入一个整数 nn 表示 Flash 的操作个数。
接下来 nn 行,每行首先输入一个字符串 opop 表示 Flash 在浏览器中的操作类型,为 back, forward 和 visit 之一。若 opop 为 visit 则在 opop 空一个空格后输入一个字符串 urlurl 表示新网页地址,否则本行无其他内容。
字符串 urlurl 仅包含英文字母,字符 ‘:’ ,字符 ‘.’ 和字符 ‘/’,长度为 ∣url∣∣url∣。
对于 10%10% 的数据,有 1≤n≤1021≤n≤102;
对于 30%30% 的数据,有 1≤n≤1031≤n≤103;
对于 100%100% 的数据有,有 1≤n≤105,1≤∣url∣≤301≤n≤105,1≤∣url∣≤30。
输出描述
对于每次操作,输出一个网址表示 The__Flash 当前操作完成后访问的网址。
样例
Sample1
输入
12 visit https://codeforces.com/ visit https://atcoder.jp/ back back back forward visit https://vjudge.net/ back back forward forward forward
输出
https://codeforces.com/ https://atcoder.jp/ https://codeforces.com/ https://www.baidu.com/ https://www.baidu.com/ https://codeforces.com/ https://vjudge.net/ https://codeforces.com/ https://www.baidu.com/ https://codeforces.com/ https://vjudge.net/ https://vjudge.net/
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<string>st1;
stack<string>st2;
int n;
cin>>n;
string now="https://www.baidu.com/";
while(n--){
string temp;
cin>>temp;
if(temp=="visit"){
cin>>temp;
st1.push(now);
now=temp;
while(!st2.empty())st2.pop();
cout<<now<<endl;
}
else if(temp=="back"){
if(now=="https://www.baidu.com/"){
cout<<now<<endl;
continue;
}
st2.push(now);
now=st1.top();
st1.pop();
cout<<now<<endl;
}else if(temp=="forward"){
if(st2.empty()){
cout<<now<<endl;
continue;
}
st1.push(now);
now=st2.top();
cout<<now<<endl;
if(!st2.empty()){
st2.pop();
}
}
}
}