1 条题解
-
0
C++ :
#include <cstdio> int main(){ int n; if(scanf("%d",&n)!=1) return 0; int a[105]; for(int i=0;i<n;i++)scanf("%d",&a[i]); int best=-1,bs=-1,bdir=0; int i=0; while(i<n){ if(i+1<n&&a[i+1]>a[i]){ int j=i; while(j+1<n&&a[j+1]>a[j])j++; if(j-i+1>best){best=j-i+1;bs=i;bdir=1;} i=j; } else if(i+1<n&&a[i+1]<a[i]){ int j=i; while(j+1<n&&a[j+1]<a[j])j++; if(j-i+1>best){best=j-i+1;bs=i;bdir=-1;} i=j; } else i++; } if(best<2){printf("%d\n",a[0]);return 0;} for(int k=0;k<best;k++){ if(k)printf(" "); printf("%d",a[bs+k]); } printf("\n"); return 0; }
- 1
信息
- ID
- 2754
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者