本文主要是介绍Web Navigation POJ 1028 栈操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
模拟平时上网打开网页的操作,值得注意的是,如果BACK回一个网页之后进行VISIT操作,之前的网页FORWARD都回不去了
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stack>
using namespace std;
#define MAXD 20
#define MAX_SIZE 100 + 10
const char start_page[] = {"http://www.acm.org/"};
int main(){int now_page = 0;int top = 0;char ord[MAXD];char web[MAX_SIZE][MAX_SIZE];strcpy(web[top++],start_page);for(;scanf("%s",ord);){if(strcmp(ord,"QUIT") == 0) break;else if(strcmp(ord,"VISIT") == 0){top = now_page + 1;scanf("%s",web[top++]);now_page += 1;printf("%s\n",web[now_page]);}else if(strcmp(ord,"BACK") == 0){now_page -= 1;if(now_page >= 0)printf("%s\n",web[now_page]);else{now_page = 0;printf("Ignored\n");}}else if(strcmp(ord,"FORWARD") == 0){if(now_page + 1 < top){now_page += 1;printf("%s\n",web[now_page]);}else{printf("Ignored\n");}}}return 0;
}
这篇关于Web Navigation POJ 1028 栈操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!