poj1028解题报告
//gcc AC: #include<stdio.h> #include<string.h> //stack related region// #define MAX_STACK_SIZE 101 #define MAX_CHAR_NUM 71 char backward[MAX_STACK_SIZE][MAX_CHAR_NUM]; char forward[MAX_STACK_SIZE][MAX_CHAR_NUM]; int index_bw; int index_fw; char read_cmd[10],read_url[MAX_CHAR_NUM]; char currentURL[MAX_CHAR_NUM]; void init() { strcpy(currentURL,"http://www.acm.org/"); index_bw = 0; index_fw = 0; } void back_process() { if (index_bw==0) { printf("Ignored\n"); return; } else { strcpy(forward[index_fw++],currentURL); strcpy(currentURL,backward[--index_bw]); printf("%s\n",currentURL); } } void forward_process() { if (index_fw==0) { printf("Ignored\n"); return; } else { strcpy(backward[index_bw++],currentURL); strcpy(currentURL,forward[--index_fw]); printf("%s\n",currentURL); } } void visit_process() { strcpy(backward[index_bw++],currentURL); strcpy(currentURL,read_url); index_fw = 0; printf("%s\n",currentURL); } int main() { init(); while (scanf("%s",&read_cmd)) { if (0==strcmp(read_cmd,"QUIT")) break; if (0==strcmp(read_cmd,"BACK")) { back_process(); } else if (0==strcmp(read_cmd,"FORWARD")) { forward_process(); } else if (0==strcmp(read_cmd,"VISIT")) { scanf("%s",&read_url); visit_process(); } } return 0; }
完全按照题目提示写就可以了。。。