随机生成一个序列从前往后寻找5个数ai是否满足a1<a2<a3<a4<a5
#include<stdio.h> #define M 2147483647 int Scan() { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9' ) res = res * 10 + ch - '0'; return flag ? -res : res; } int main() { int a,n,a1,a2,a3,a4,a5; while(scanf("%d",&n)!=EOF) { a1=a2=a3=a4=a5=M; while(n--) { a=Scan(); if(a<=a1) a1=a; else if(a<=a2) a2=a; else if(a<=a3) a3=a; else if(a<=a4) a4=a; else if(a<=a5) a5=a; } if(a5<M) printf("YES "); else printf("NO "); } }