题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include <iostream> using namespace std; int main() { int k; while (cin >> k) { int jz[k]; for(int i=0;i<k;i++) { cin>>jz[i]; } for(int i=0;i<k;i++) { if(i==0) { if(jz[0]<jz[1]||jz[0]>jz[1]) { cout<<i<<" "; } } else if(i==(k-1)) { if(jz[i]<jz[i-1]||jz[i]>jz[i-1]) { cout<<i<<" "; } } else{ if(((jz[i]<jz[i-1])&&(jz[i]<jz[i+1]))||((jz[i]>jz[i-1])&&(jz[i]>jz[i+1]))) { cout<<i<<" "; } } } cout<<endl; } }