您的位置:首页 > 产品设计 > UI/UE

1051. Pop Sequence (25)

2017-02-14 22:47 513 查看
根据序列模拟窄的压窄出窄情况

#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
int M, N, K;
cin >> M >> N >> K;
string str;
while (K--)
{
stack<int> sta;
int i = 1;
for (int t = 0;t < N;t++)
{

int temp;
cin >> temp;
while ((sta.empty()|| sta.top() != temp) && i <= N) sta.push(i++);
if (sta.top() == temp && sta.size()<=M) sta.pop();
else {
cout << "NO" << endl;getline(cin, str);break;
}
if (t == N - 1) { cout << "YES" << endl;break; }
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PAT-甲