http://acm.pku.edu.cn/JudgeOnline/problem?id=1028
Код:
#include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> v; vector<string>::iterator p; string c,s; v.push_back("http://www.acm.org/"); p=v.end(); while(cin >> c) { if(c=="QUIT") break; if(c=="VISIT") { cin >> s; cout << s << endl; v.erase(p, v.end()); v.push_back(s); p=v.end(); } else if(c=="BACK") { if(p==v.begin()+1) cout << "Ignored\n"; else { --p; cout << *(p-1) << endl; } } else if(c=="FORWARD") { if(p==v.end()) cout << "Ignored\n"; else { ++p; cout << *(p-1) << endl; } } } return 0; }