【例题 6-2 UVA - 514】Rails

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】
栈模拟一下就好。
每个输出段后面都有一个空行。
包括最后一个.

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1000;

int n,a[N+10],bo[N+10];//bo = 1-> inque bo = 2->instack
stack <int> sta;

bool ok(int n)
{
    while (!sta.empty()) sta.pop();
    int now = 1;//inque first
    for (int i = 1;i <= n;i++) bo[i] = 1;
    for (int i = 1;i <= n;i++)
    {
        while (bo[a[i]]==1)
        {
            sta.push(now);
            bo[now++] = 2;
        }
        if (sta.top()!=a[i]) return false;
        sta.pop();
    }
}

int main()
{
    while (~scanf("%d",&n) && n)
    {
		while (scanf("%d",&a[1]) && a[1])
		{
			for (int i = 2;i <= n;i++) scanf("%d",&a[i]);
			if (ok(n))
				puts("Yes");
			else
				puts("No");
		}
		puts("");
    }
    return 0;
}

posted @ 2017-10-19 09:33  AWCXV  阅读(94)  评论(0)    收藏  举报