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

一直都是RE

Posted by 627757940 at 2014-02-10 21:31:39 on Problem 1028
一直都是RE,我开始以为是因为网址太长,导致越界,就把字符数组的容量开到1000,但也是RE,就没想明白了,求各位大大解释,代码如下:
typedef char* ElementType_Stack;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*Header Used*/
#ifndef STDIO
#define STDIO 1
#include <stdio.h>
#endif

#ifndef STDLIB
#define STDLIB 1
#include <stdlib.h>
#endif

#define STACK 1

struct stack_tag;
typedef struct stack_tag * PtrToStackTag;
typedef PtrToStackTag stack;
typedef PtrToStackTag Position_Stack;

struct stack_tag
{
	ElementType_Stack data;
	stack next;
};

stack NewStack(void)
{
	stack header;
	header  = (stack)malloc(sizeof(struct stack_tag));
	if(header == NULL){
		return header;	
	}else{
		header->next == NULL;
		return header;
	}
}

int IsEmpty(stack S)
{
	return (S->next == NULL);
}

ElementType_Stack pop(stack S)
{
	ElementType_Stack x;
	Position_Stack tmp;

	x = S->next->data;
	tmp = S->next;
	S->next = tmp->next;
	free(tmp);
	return x;
}

ElementType_Stack top(stack S)
{
	return S->next->data;
}

void push(ElementType_Stack x,stack S)
{
	Position_Stack tmp;

	tmp = (stack)malloc(sizeof(struct stack_tag));
	tmp->data = x;
	tmp->next = S->next;
	S->next = tmp;
}

void delete(stack S)
{
	Position_Stack p = S->next;
	
	while(S->next != NULL){
		free(S);
		S = p;
		p = S->next;
	}
	free(S);
}

void MakeEmpty(stack S)
{
	while(!IsEmpty(S)){
		pop(S);
	}
}

char home[] = "http://www.acm.org/";

int main()
{
	stack forward,backward;
	char *cur,order[] = "FORWARD";
//	FILE *in;
	
//	in = fopen("input.c","r");
	forward = NewStack();
	backward = NewStack();
	cur = (char *)malloc(sizeof(char) * 101);
	strcpy(cur,home);
	while(scanf("%s",order) && strcmp(order,"QUIT") != 0){
		if(strcmp(order,"FORWARD") == 0){
			push(cur,backward);
			if(IsEmpty(forward)){
				printf("Ignored\n");
			}else{
				cur = pop(forward);
				printf("%s\n",cur);
			}
		}else if(strcmp(order,"BACK") == 0){
			if(IsEmpty(backward)){
				printf("Ignored\n");
			}else{
				push(cur,forward);
				cur = pop(backward);
				printf("%s\n",cur);
			}
		}else{
			push(cur,backward);
			cur = (char *)malloc(sizeof(char) * 101);
			scanf("%s",cur);
			printf("%s\n",cur);
			MakeEmpty(forward);
		}
	}
	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