题目:https://www.patest.cn/contests/pat-a-PRactise/1051
代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath>#include<stack>#include<string>#include<iostream>#include<algorithm> using namespace std; int main() { stack<int> s; int m,n,k; int a[1010]; scanf("%d%d%d",&m,&n,&k); while(k--){ bool flag=true; int temp=1; while(!s.empty()){ s.pop(); } for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=1;i<=n;i++){ s.push(i); if(s.size()>m){ flag=false; break; } while(!s.empty()&&s.top() == a[temp]){ s.pop(); temp++; } } if(s.empty() == true && flag == true){ printf("YES/n"); }else{ printf("NO/n"); } } system("pause"); }
新闻热点
疑难解答