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

找不到问题总是WA,求大侠帮助小弟不成熟的代码

Posted by 1120101777 at 2011-07-06 19:58:42 on Problem 1028
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
struct browser
{
	char web[5000];
    struct browser *p;
};
typedef struct browser BROWSER;
typedef BROWSER *BMW;
BMW forward=NULL;
BMW backward=NULL;
void push(char a,char *p)
{
	BMW newnode;
    newnode=(BMW)malloc(sizeof(BROWSER));
    strcpy(newnode->web,p);
	if(a=='F')
	{
	newnode->p=forward ;
	forward=newnode;
	}
	else
	{
		newnode->p=backward;
		backward=newnode;
	}
}
char *pop(char a)
{
	BMW top;
	char *q;
    if(a=='F')
	{
	  if(forward!=NULL)
	  {
      top=forward;
	  forward=forward->p;
	  q=top->web;
	  return q;
	  }
	  else return(NULL);
	}
	else
	{
		if(backward!=NULL)
		{
		top=backward;
		backward=backward->p;
		q=top->web;
	    return q;
		}
		else return(NULL);
	}
}
void qingkong()
{
	forward=NULL;
}
void main()
{
	char web[5000],t=0,acm[]="http://www.acm.org/\0",web2[5000],web3[5000];
	char *p;
	p=&acm[0];
	while(1)
	{
		gets(web);
		if(strcmp(web,"QUIT")==0) break;
        if(strcmp(web,"BACK")==0)
		{	
			p=pop('B');
			if(p!=NULL)
			{ 
			puts(p);
			push('F',web3);
			strcpy(web3,p);
			}
		   else printf("Ignored\n");
		}
		if(strcmp(web,"FORWARD")==0)
		{
			if(t!=0)
			push('B',web3);
			p=pop('F');
			if(p!=NULL){ 
				puts(p);
				strcpy(web3,p);
			}
			else  
			 printf("Ignored\n");
			 
		}
		if(web[0]=='V')
		{	
			push('B',p);
			strcpy(web2,web);	
			p=&web2[6];
			strcpy(web3,p);
			puts(p);
			qingkong();
			t++;
		}	
	}
}
 
		

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