题解 | #非递减序列#
非递减序列
http://www.nowcoder.com/practice/752409657fee4fddbac587fb30fd59b6
#include <bits/stdc++.h>
using namespace std;
int main(){
int m;
stack<int> v;
int c=0;
while(cin>>m){
if(v.empty()) v.push(m);
else if(m<v.top()&&c==0) {//遇到第一个不满足条件的数
v.pop();
if(!v.empty()&&m<v.top()) {
cout<<0<<endl;return 0;
}
else if(v.empty()){
v.push(m);
v.push(m);
}
else {
v.push(v.top());
v.push(m);}
c++;
}else if(m<v.top()&&c){
cout<<0<<endl;
return 0;
}else v.push(m);
}
cout<<1<<endl;
return 0;
}