题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include <iostream> using namespace std; const int MAXN = 80 + 10; int a[MAXN]; int main () { int n; while (scanf ("%d", &n) != EOF){ for (int i = 0; i < n; i++){ scanf ("%d", &a[i]); } for (int i = 0; i < n; i++){ if (i == 0){ if (a[i + 1] != a[i]){ cout << i << " "; } }else if (i == n - 1){ if (a[i] != a[i - 1]){ cout << i << " "; } }else if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]){ cout << i << " "; } } cout << endl; } return 0; }