B - Rails
程序员文章站
2022-07-13 17:58:56
...
#include<iostream>
#include<string.h>
#include<string>
#include<stack>
#include<stdlib.h>
#include<vector>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int n;
vector<int> block[30];
int t[1010];
int main()
{
int a, b,i,flag;
while (~scanf("%d", &n)&&n)
{
while (scanf("%d", &t[0]), t[0])
{
a = flag = 1;
b = 0;
for (i = 1; i < n; i++)
scanf("%d", &t[i]);
stack<int>s;
while (b < n)
{
if (a == t[b])
{
a++;
b++;
}
else if (!s.empty() && s.top() == t[b])
{
s.pop();
b++;
}
else if (a <= n)
{
s.push(a++);
}
else
{
flag = 0;
break;
}
}
if (flag == 1)
printf("Yes\n");
else
printf("No\n");
}
printf("\n");
}
return 0;
}
上一篇: 1 Github入门