题意:<看图片>
解题思路:栈的简单应用:
#include<iostream> #include<stack> #include<algorithm> using namespace std; int main () { int N,data[1005],flag=1; while(~scanf("%d",&N)&&N) { while(1) { for(int i=1;i<=N;i++){ flag=1; scanf("%d",&data[i]); if(data[1]==0){flag=0;break;} } if(!flag) break; else{ stack<int>st; int A=1,B=1; int ok=1; while(B<=N){ if(A==data[B]){A++;B++;} else if(!st.empty()&&st.top()==data[B]){st.pop();B++;} else if(A<=N)st.push(A++); else {ok=0;break;} } printf("%s ",ok==1?"Yes":"No"); } } printf(" "); } return 0; }