题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include <stdio.h> int main() { int n; while ((scanf("%d", &n)) != EOF) { int Arr[n]; for (int i = 0; i < n; i++) { scanf("%d", &Arr[i]); } int Brr[n]; int k = 0; for (int j = 0; j < n; j++) { if (j == 0 && (Arr[j] != Arr[j + 1])) { Brr[k++] = j; } else if (j == n - 1 && (Arr[j] != Arr[j - 1])) { Brr[k++] = j; } else if ((Arr[j] > Arr[j + 1] && Arr[j] > Arr[j - 1]) || (Arr[j] < Arr[j + 1] && Arr[j] < Arr[j - 1])) { Brr[k++] = j; } } for (int l = 0; l < k; l++) { printf("%d ", Brr[l]); } printf("\n"); } return 0; }