作者在 2013-12-25 22:12:31 发布以下内容
问题描述:火车分n小节,从头开始进站出站,有可能的顺序
#include<fstream>
#include<sstream>
#include<iostream>
#include<stack>
using namespace std;
int main(){
ifstream in("rail.txt");
for(int n,line=0;in>>n&&n&&in.ignore();){
cout<<(line++ ? "\n":"");
for(string s;getline(in,s)&&s!="0";){
istringstream sin(s);
stack<int> st;
for(int last=0,coach;sin>>coach;st.pop()){
for(int p=last+1;p<=coach;++p) st.push(p);
if(last<coach) last=coach;
if(st.top()!=coach) break;
}
cout<<(!sin? "Yes\n":"No\n");
}
}
}
//rail.txt
5
3 2 1 5 4
5 4 1 2 3
0