模拟题目所述的浏览器的各种操作,使用一个curWebsite变量来保存当前的Page。
/*Problem: 1028 User: DragonKnightMemory: 712K Time: 79MSLanguage: G++ Result: Accepted*/#include#include #include using namespace std;int main(){ string command, website; stack back,forward;//前进栈,后退栈 string curWebsite = "http://www.acm.org/";//初始载入的页面 while(cin >> command) { if(command == "QUIT") { break; } else if(command == "VISIT") { cin >> website; back.push(curWebsite); curWebsite = website; cout << curWebsite << endl; while(!forward.empty()) forward.pop(); } else if(command == "BACK") { if(!back.empty()) { forward.push(curWebsite); curWebsite = back.top(); back.pop(); cout << curWebsite << endl; } else { cout << "Ignored" << endl; } } else if(command == "FORWARD") { if(!forward.empty()) { back.push(curWebsite); curWebsite = forward.top(); forward.pop(); cout << curWebsite << endl; } else { cout << "Ignored" << endl; } } } return 0;}