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

help!!!!!!!!为什么错了啊

Posted by hehejj at 2005-09-12 19:02:03 on Problem 1363
# include<iostream.h>
# include<assert.h>
# include<math.h>

class Stack
{
	public:
		Stack(int);
		~Stack() { delete[]elements;}
		void Push(int&);
		int Pop();
		int GetTop();
		void MakeEmpty() {top=-1;}
		int IsEmpty()const { return top==-1;}
		int IsFull()const { return top==maxSize-1;}
	private:
		int top;
		int *elements;
		int maxSize;
};

Stack::Stack(int s)
{
	top=-1,maxSize=s;

	elements=new int[maxSize];
}

void Stack::Push(int & number)
{
	assert(!IsFull());
	elements[++top]=number;
}

int Stack::Pop()
{
	assert(!IsEmpty());
	return elements[top--];
}

int Stack::GetTop()
{
	if(!IsEmpty())
		return elements[top];
	else
		return 0;
}
void main()
{
	int numofcoach;
	int i,j,sign=1;
	int temp;
	while(1)
	{
		cin>>numofcoach;
		if(numofcoach==0)
			break;		
		//if(sign==0)
			cout<<endl;
		/*if(sign==1)
			sign=0;*/
		while(1)
		{
			Stack *a=new Stack(numofcoach+1);
			Stack *b=new Stack(numofcoach);
			for(i=numofcoach+1;i>=1;i--)
				a->Push(i);
			for(i=0;i<numofcoach;i++)
			{
				cin>>temp;
				if(temp==0)
					break;
				if(temp>=a->GetTop())
				{
					for(j=a->GetTop();j<=temp;j++)
					{
						a->Pop();
						b->Push(j);
					}
					b->Pop();
				}				

				else if(temp==b->GetTop())
					b->Pop();				
							
				else
				{
					for(i++;i<numofcoach;i++)
						cin>>temp;
					numofcoach--;
					cout<<"No"<<endl;
					break;
				}			
			}
			if(i==numofcoach)
				cout<<"Yes"<<endl;			
			delete a;
			delete b;
			if(temp==0)
				break;
		}
	}
}

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