Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用链表一目了然

Posted by wws at 2015-02-05 20:50:10 on Problem 1028
这一题很适合用链表啊,按照题目的方法能实现,但是有些绕,贴上我的代码.
(好几次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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator