您的位置:首页 > 大数据 > 人工智能

算法竞赛入门经典第六章例题6-2 Rails UVA - 514

2018-01-16 20:18 381 查看
https://vjudge.net/problem/UVA-514

#include<iostream>
#include<stack>
using namespace std;
#pragma warning(disable:4996)

int main(){
#ifdef _DEBUG
//freopen("in", "r", stdin);
//freopen("out", "wb", stdout);
#endif // _DEBUG
int N;
while (cin >> N && N) {
int a[1005];
while (cin >> a[0] && a[0]) {
for (int i = 1; i < N; ++i)
cin >> a[i];
bool _ok = 1;
stack<int> sta;
int x = 1;
for (int i = 0; i < N; ++i)
if (x <= a[i]) {
while (x != a[i]) sta.push(x++);
++x;
}
else if (a[i] == sta.top()) sta.pop();
else { _ok = 0; break; }
cout << (_ok ? "Yes" : "No") << endl;
}
cout << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: