3 123 321 3 123 312
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH
For the first Sample Input, we let train 1 get in, then train 2 and train 3.
So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.
Now we can let train 3 leave.
But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.
So we output "No.".
Hint
#include <iostream>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n;
while(cin>>n && n)
{
getchar();
char str[15],mod[15];
scanf("%s%*c%s%*c",str,mod);
stack<char> st;
while(!st.empty())
st.pop();
int i, j;
bool step[100];
int k=0,sum=0;
for(i=0,j=0 ;i<=n && j<n && sum <= 9 ;i++)
{
st.push(str[i]);
step[k++]=1;
sum++;
while(!st.empty() && st.top()==mod[j])
{
st.pop();
step[k++]=0;
j++;
sum--;
}
}
if(st.empty()&&( i>n || j>=n ))
{
cout<<"Yes."<<endl;
for(i=0 ; i<k ; i++)
{
if(step[i])
{
cout<<"in"<<endl;
}
else
{
cout<<"out"<<endl;
}
}
cout<<"FINISH"<<endl;
}
else
{
cout<<"No."<<endl<<"FINISH"<<endl;
}
}
return 0;
}
233



被折叠的 条评论
为什么被折叠?



