标签:技术分享 first style get 位置 mon blocks eth empty
Description

Input
Output
Sample Input
5 1 2 3 4 5 5 4 1 2 3 0 6 6 5 4 3 2 1 0 0
Sample Output
Yes No Yes
#include<stdio.h>
int main()
{
int input[1005],output[1005],cnt,j,i,n;
while(scanf("%d",&n),n) //输入列车节数
{
while(scanf("%d",&output[0]),output[0])
{
for(j=1; j<n; j++)
scanf("%d",&output[j]); //输入出栈的顺序
for(cnt=1,j=0,i=0; cnt<=n;) //cnt表示对进站时列车编号,并在编号完毕后退出
{
input[i]=cnt;
//在编号时,假设遇到相应位置同样的出站编号。进入循环。进站顺序向后。出站顺序向前相应,相应成功继续循环
while(input[i]==output[j])
{
i--;
j++; //每当相应成功。位置向后移。看是否还能相应
//i==-1时,代表进站的车厢相应到达顶端,之前的车厢一定相应成功,代表从刚进入循环时到这里所经历的车厢可以成功出站
if(i==-1)
break;
}
i++;
cnt++;
}
if(j==n) //假设成功出站。那么对于出站列车,每节车厢都相应成功
printf("Yes\n");
else
printf("No\n");
}
printf("\n");
}
}
标签:技术分享 first style get 位置 mon blocks eth empty
原文地址:http://www.cnblogs.com/blfbuaa/p/7063100.html