模拟没超时- -
- //============================================================================
- // Name : 1028.cpp
- // Author : kevin
- // Version :
- // Copyright : copyright @ kevin
- // Description : Hello World in C++, Ansi-style
- //============================================================================
- #include <iostream>
- #include<stack>
- #include<string>
- using namespace std;
- int main() {
- stack<string> forwardStack;
- stack<string> backStack;
- string currentPage="http://www.acm.org/";
- const int MAX=100;
- char str[MAX];
- char op[10];
- cin>>op;
- while(op[0]!='Q'){
- if(op[0]=='V'){
- cin>>str;
- cout<<str<<endl;
- backStack.push(currentPage);
- while(!forwardStack.empty())
- forwardStack.pop();
- currentPage=str;
- }
- if(op[0]=='B'){
- if(!backStack.empty()){
- forwardStack.push(currentPage);
- currentPage=backStack.top();
- backStack.pop();
- cout<<currentPage<<endl;
- }else
- cout<<"Ignored"<<endl;
- }
- if(op[0]=='F'){
- if(!forwardStack.empty()){
- backStack.push(currentPage);
- currentPage=forwardStack.top();
- forwardStack.pop();
- cout<<currentPage<<endl;
- }else
- cout<<"Ignored"<<endl;
- }
- cin>>op;
- }
- return 0;
- }