难度:2
栈的简单应用
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
int main() {
int n;
while (cin >> n && n) {
int x;
while (cin >> x && x) {
vi v;
v.pb(x);
for (int i = 1; i < n; i++) {
cin >> x;
v.pb(x);
}
stack<int> st;
int pos = 0;
for (int i = 1; i <= n; i++) {
st.push(i);
while (st.size() > 0 && st.top() == v[pos]) {
st.pop();
pos++;
}
}
cout << (pos == n ? "Yes" : "No") << endl;
}
cout << endl;
}
return 0;
}