| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这道题用STL中的stack会有问题么?仿照书上的写了个,结果无输出...只好自己写类实现,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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator