Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
虽然 有个问题 纠结了一段时间 但是还是一次AC感觉不错 贴上幼稚代码#include<stdio.h> #include<string.h> #define MAX 10 char back[101][75] , ahead[101][75] ; char URL[75]; int bt = 0 , at = 0 ; void push( char stack[101][75] ,int &top){ strcpy(stack[++top] , URL) ; } int pop(char stack[101][75] , int &top){ strcpy(URL , stack[top--]) ; return 1 ; } void dvisit(){ push(back , bt) ; scanf("%s" ,URL) ; at = 0 ; printf("%s\n" , URL) ; } void dback(){ if(!bt) printf("Ignored\n") ; else{ push(ahead , at) ; pop(back , bt) ; printf("%s\n" , URL) ; } } void forword(){ if(!at) printf("Ignored\n") ; else{ push(back , bt) ; pop(ahead , at) ; printf("%s\n" , URL) ; } } int trans(char cmd[MAX]){ if(!strcmp(cmd , "VISIT")) return 1 ; if(!strcmp(cmd , "BACK")) return 2 ; if(!strcmp(cmd , "FORWARD")) return 3 ; if(!strcmp(cmd , "QUIT")) return 0 ; else return 0 ; } int docmd(int c){ switch(c){ case 1 : dvisit() ;return 1 ; case 2 : dback() ;return 2 ; case 3 : forword() ; return 3 ; case 0 : return 0 ; } return 0 ; } int main() { char cmd[MAX] ; strcpy(URL , "http://www.acm.org/") ; while(scanf("%s" , cmd) , docmd(trans(cmd))) ; return 0 ; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator