题目:https://www.luogu.org/problemnew/show/T34983
思路:模拟,用两个vector代替链表。
代码:
#include<bits/stdc++.h>
using namespace std;
vector<string> flist;
vector<string> blist;
void slv(){
char opr[10];
string a="http://www.acm.org/";
while(~scanf("%s",opr)&&opr[0]!='Q'){
if(opr[0]=='V'){
blist.push_back(a);
cin>>a;
flist.clear();
cout<<a<<endl;
}
if(opr[0]=='F') {
if(flist.empty()){
printf("Ignored\n");
continue;
}
blist.push_back(a);
a=flist[flist.size()-1];
flist.pop_back();
cout<<a<<endl;
}
if(opr[0]=='B') {
if(blist.empty()){
printf("Ignored\n");
continue;
}
flist.push_back(a);
a=blist[blist.size()-1];
blist.pop_back();
cout<<a<<endl;
}
}
}
int main(){
slv();
return 0;
}
本文介绍了一种使用两个 vector 模拟浏览器历史记录的方法,实现网页的前进和后退功能。通过输入不同的指令,可以完成对当前网页地址的更改,并能够记录用户的浏览历史。
3183

被折叠的 条评论
为什么被折叠?



