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,都要跳楼了!Help!!!!!!!

Posted by shengye_205 at 2007-05-13 16:04:14 on Problem 1028
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
int const StackMaxSize=100;
struct Stack
{
	char stack[StackMaxSize][80];
	int top;
};
void Push(Stack & S,const char item[],int n)
{
	if(S.top==StackMaxSize-1)
	{
		cerr<<"Stack overflow!"<<endl;
		exit(1);
	}
	S.top++;
	strcpy(S.stack[S.top],item);
}
char* Pop(Stack & S,char a[],int n)
{
	if(S.top==-1)
	{
		char *p="Ignored";
		return p;
	}
	else
	{
		a=S.stack[S.top];
		S.top--;
		return a;
	}
}
Stack Sb,Sf;

void main()
{
	Sb.top=Sf.top=-1;
	char *a=new char [80];
	strcpy(a,"http://www.acm.org/ ");
	char p[80]="";
	cin>>p;
	while(strcmp(p,"QUIT")!=0)
	{
		if(p[0]=='V')
		{
	        cin>>p;
			while(Sf.top!=-1)
				Sf.top--;
			
			Push(Sb,a,80);
		
			strcpy(a,p);
			for(int i=0;i<(int)strlen(a);i++)
				cout<<a[i];
			cout<<endl;
		}
		else if(p[0]=='B')
		{
	
			if(Sb.top==-1)
			
				cout<<"Ignored"<<endl;
			
			else
			{
				Push(Sf,a,80);
				a=Pop(Sb,a,80);
				for(int i=0;i<(int)strlen(a);i++)
					cout<<a[i];
				cout<<endl;
			}
		}
		else if(p[0]=='F')
		{
			if(Sf.top==-1)
				cout<<"Ignored"<<endl;
			else{
				Push(Sb,a,80);
				a=Pop(Sf,a,80);
				for(int i=0;i<(int)strlen(a);i++)
					cout<<a[i];
				cout<<endl;
			}
		}
		cin>>p;
	}
}

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