题目意思:
模拟浏览器, 前进 ,后退,访问新的网页等功能。每一个命令,都要显示当前的网址。
注意:
1、 STL 水题, 用两个 vector 或者 stack 模拟即可
2、 vector v1, v2;
v1 存放的是当前以及之前的 web(每次当前的网页 web 都要放在 v1 的最后一个位置)
v2 存放的是 当前页面之后的 web
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;int main()
{
string line, cmd, web;vector<string> v1, v2;v1.push_back("http://www.acm.org/");while(getline(cin, line)){
if(line[0] == 'V'){
istringstream iss(line); iss >> cmd >> web;v1.push_back(web);v2.clear(); cout << web << endl;}else if(line[0] == 'B'){
if(v1.size() < 2) {
cout << "Ignored" << endl; }else{
v2.push_back(v1[v1.size() - 1]);v1.pop_back();cout << v1[v1.size() - 1] << endl;}}else if(line[0] == 'F'){
if(v2.size() == 0){
cout << "Ignored" << endl;}else{
cout << v2[v2.size() - 1] << endl;v1.push_back(v2[v2.size() - 1]);v2.pop_back();}}else{
break; }}return 0;
}/* VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT *//* http://acm.ashland.edu/ http://acm.baylor.edu/acmicpc/ http://acm.ashland.edu/ http://www.acm.org/ Ignored http://acm.ashland.edu/ http://www.ibm.com/ http://acm.ashland.edu/ http://www.acm.org/ http://acm.ashland.edu/ http://www.ibm.com/ Ignored */