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 |
用链表一目了然这一题很适合用链表啊,按照题目的方法能实现,但是有些绕,贴上我的代码. (好几次WA,因为我把Ignored写成了ignored.希望以后的acm题都能忽略大小写,不然无谓的浪费时间.) #include<stdio.h> struct footprint{ char view[180]; struct footprint *next; struct footprint *prev; }; struct footprint *root; struct footprint *at; void insert(struct footprint *fprint){ fprint->next = NULL; fprint->prev = at; at->next = fprint; } int main(void){ root = malloc(sizeof(struct footprint)); strcpy(root->view, "http://www.acm.org/"); root->next = root->prev = 0; at = root; char cmd[8]; char *msg = ""; while(1){ scanf("%s", cmd); if(strcmp(cmd, "QUIT") == 0) return 0; else if(strcmp(cmd, "BACK") == 0){ if(at == root) msg = "Ignored"; else{ at = at->prev; msg = at->view; } } else if(strcmp(cmd, "FORWARD") == 0){ if(at->next == NULL) msg = "Ignored"; else{ at = at->next; msg = at->view; } } else if(strcmp(cmd, "VISIT") == 0){ struct footprint * fp = malloc(sizeof(struct footprint)); scanf("%s", fp->view); insert(fp); at = fp; msg = at->view; } else msg = "Ignored"; printf("%s\n", msg); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator