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

这道题用STL中的stack会有问题么?

Posted by Redwood at 2007-10-15 16:06:27 on Problem 1363
仿照书上的写了个,结果无输出...只好自己写类实现,STL为什么会有问题呢??
#include<iostream>
#include<stack>                                           //用c++STL中的栈来实现
using namespace std;

int Num;                                                  //车厢总数             
int Out;                                                  //即将出站的车厢编号
int In;                                                   //将要入站的车厢编号
int main()
{
	int count;
	cin>>Num;
	while(Num!=0)
	{
		cin>>Out;
		while(Out!= 0)
		{
			
			In = 1;
			stack<int> Stack;
			for(count = 1;count<Num;count++)
			{
				if(Out<Stack.top())
					break;
				if(Out == Stack.top())
				{
					Stack.pop();
					cin>>Out;
				}
				if(Out>Stack.top()||Stack.empty())
				{
					for(In = Stack.top()+1;In<=Out;In++)
						Stack.push(In);
					Stack.pop();
					cin>>Out;
				}
				
			} 

			if(count == Num)
				cout<<"Yes"<<endl;
			else
				cout<<"No"<<endl;
			cin.ignore(4000,'\n');
			cin>>Out;
		}
		cout<<endl;
		cin>>Num;
	}
 
	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