'commit'
This commit is contained in:
27
GESP/Mkx/CheXiangDiaoDu.cpp
Normal file
27
GESP/Mkx/CheXiangDiaoDu.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, target;
|
||||
stack<int> st;
|
||||
cin >> n;
|
||||
|
||||
int cur = 1; // 当前待入栈数字
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> target; // 读取目标出站值
|
||||
|
||||
// 当前目标值未入栈,持续入栈直到包含目标值
|
||||
while (cur <= target)
|
||||
st.push(cur++);
|
||||
|
||||
// 栈顶匹配则出栈
|
||||
if (!st.empty() && st.top() == target) {
|
||||
st.pop();
|
||||
} else {
|
||||
cout << "NO" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
cout << "YES" << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user