题意:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int num[1007];
int kase = 0;
while(scanf("%d", &n) != EOF && n != 0)
{
while(scanf("%d", &num[0]) && num[0] != 0){
stack<int> s1;
num[1] = num[0];
for(int i = 2; i <= n; i++){
scanf("%d", num+i);
}
int ok = 0;
int A = 1, B = 1;
while(B <= n){
if(A == num[B]){A++; B++;}
else if(!s1.empty() && s1.top() == num[B]){s1.pop(); B++;}
else if(A <= n) s1.push(A++);
else {ok =0; break;};
}
if(ok) printf("Yes
");
else printf("No
");
}
printf("
");
}
}