http://poj.org/problem?id=1028
题目大意:默认主页为“http://www.acm.org/”,输入为指令,输出为当前网站的网址。输入的指令有四种:
(1)VISIT 访问一个新的网站
(2)BACK 返回之前访问的网站
(3)FORWARD 前往后一个访问的网站
(4)QUIT 退出
直接开个数组记录一下,模拟就行
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> using namespace std; template <class T> void checkmin(T &t,T x) {if(x < t) t = x;} template <class T> void checkmax(T &t,T x) {if(x > t) t = x;} template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;} template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;} typedef pair <int,int> PII; typedef pair <double,double> PDD; typedef long long ll; #define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++) char s[1010][100] , od[100]; int cnt = 1 , pos = 1; int main() { while(~scanf("%s",od)) { strcpy(s[1],"http://www.acm.org/"); if(od[0] == 'Q') break; else if(od[0] == 'V') { pos ++; cnt = pos; scanf("%s",s[cnt]); printf("%s\n",s[cnt]); } else if(od[0] == 'B') { if(pos == 1) printf("Ignored\n"); else printf("%s\n" , s[--pos]); } else if(od[0] == 'F') { if(pos == cnt) printf("Ignored\n"); else printf("%s\n" , s[++pos]); } } return 0; }