Topic 1126: Printing Extreme point subscript
time limit:1 seconds
Memory limit:32 MB
Special question: No
-
Title Description:
-
On an array of integers, for an integer that is subscript I, if it is greater than all of its adjacent integers,
or less than all of its adjacent integers, then called the integer is an extremum point, the subscript of the extremum point is I.
-
Input:
-
The input for each case is as follows:
There is 2xn+1 line input: The first line is the number of arrays to be processed n;
For the remaining 2xn rows, the first row is the number of elements in this array K (4<k<80), the second row is a K integer, and each two integers are separated by a space.
-
Output:
-
Each case output is n rows: Each line corresponds to the subscript value of all extremum points in the corresponding array, and the subscript values are separated by a space.
-
Sample input:
-
31010 12 12 11 11 12 23 24 12 121512 12 122 112 222 211 222 221 76 36 31 234 256 76 76 1512 14 122 112 222 222 222 221 76 36 31 234 256 76 73
-
-
Sample output:
-
0 72 3 4 5 6 10 120 2 3 10 12 14
Pay attention to the subscript
#include <iostream>#include<stdio.h>#include<stdlib.h>using namespacestd;intMain () {intN; intFlag; inta[ the]; intx; while(SCANF ("%d", &n)! =EOF) { while(n--) {scanf ("%d",&x); for(intI=0; i<x;i++) {scanf ("%d",&A[i]); } Flag=0; for(intj=0; j<x;j++) { if((j==0&& (a[0]!=a[1]))|| (j==x-1&& (a[j]!=a[j-1]))|| (a[j]>a[j-1]&&a[j]>a[j+1])|| (a[j]<a[j-1]&&a[j]<a[j+1])) { if(flag==1) {printf ("%d", J); }Else{printf ("%d", J); Flag=1; }}} printf ("\ n"); } } return 0;}
Topic 1126: Printing Extreme point subscript