64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stack>
using namespace std;
int main() {
int a[10], n = 0, i = 0, j = 0;
bool k = true;
stack<int> s[10];
cin >> n;
while (n--) {
for (i = 0; i < 10; i++) {
cin >> a[i];
}
for (i = 0; i < 10; i++) {
if (i > 0) {
if (a[i] - a[i - 1]) {
j++;
}
}
s[j].push(a[i]);
}
j = 0;
for (i = 0; i < 10; i++) {
if (s[j].empty()) {
j++;
}
if (i + 1 != s[j].top()) {
k = false;
}
s[j].pop();
}
if (k == true) {
cout << "Yes\n";
} else {
cout << "No\n";
}
j = 0, k = true;
}
return 0;
}
bool isPossible(int popSequence[], int N)
{
int n = 1, nextToPopOut;
stack<int> st;
for(nextToPopOut = 0; nextToPopOut < N; ++nextToPopOut){
while(st.empty() || st.top() != popSequence[nextToPopOut]){
if(n > N) return false;//1~N已经全部入栈过一次了,但是仍不能满足出栈顺序
st.push(n++);
}
//能运行到这里必然有st.top() = popSequence[nextToPopOut]了
st.pop();
}
return true;
}