1051. Pop Sequence (25)

来源:互联网 发布:淘宝小店描述怎么写 编辑:程序博客网 时间:2024/05/16 01:36

题目:https://www.patest.cn/contests/pat-a-practise/1051

#include<cstdio>#include<stack>using namespace std;int main(){  int M,N,K,flag = 1,x=0,temp;  int Arry[1000]={0};  stack<int> st;  scanf("%d%d%d",&M,&N,&K);  while(K--)  {    while (!st.empty())    {      st.pop();    }    int current = 1;    flag = 1;    for(int i=1; i<=N; i++)    {      scanf("%d",&Arry[i]);    }    for(int i=1; i<=N; i++)    {      st.push(i);      if(st.size()>M)      {        flag = 0;        break;      }      while (!st.empty() && st.top() == Arry[current])      {        current++;        st.pop();      }    }    if(st.empty() && flag == 1)    {      printf("YES\n");    }    else    {      printf("NO\n");    }  }  return 0;}


0 0
原创粉丝点击