Topic 1126: Printing Extreme point subscript

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.