生活随笔
收集整理的這篇文章主要介紹了
UVA514
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=455
代碼如下:
#include <iostream>
#include<cstdio>
#include<stack>
#define maxn 1005
using namespace std;
int aa[maxn];
int main()
{int n;stack<int>sta;int flag=1;while(scanf("%d",&n)!=EOF){flag=1;for(int i=1;i<=n;i++)scanf("%d",&aa[i]);int A=1,B=1;while(B<=n){if(A == aa[B]){A++;B++;}else if(!sta.empty()&&sta.top()==aa[B]){sta.pop();B++;}else if(A<=n){sta.push(A);A++;}else{flag=0;break;}}printf("%s\n",flag?"YES":"NO");}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的UVA514的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。