知识点:栈
难度:2
没啥可说的,栈的最入门的简单题,一开始写错了是因为将下标累加放到了循环头里面而不是循环体里面,明显这会出现错误,
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int main() {
int n;
while (cin >> n && n) {
int a[N];
while (cin >> a[1] && a[1]) {
for (int i = 2; i <= n; i++) cin >> a[i];
int index = 1;
stack<int> stk;
for (int i = 1; i <= n; i++) {
stk.push(i);
while (!stk.empty() && stk.top() == a[index]) {
index++;
stk.pop();
}
}
cout << (index == n + 1 ? "Yes" : "No") << endl;
}
cout << endl;
}
return 0;
}