http://ac.jobdu.com/problem.php?pid=1126
题目描述: 在一个整数数组上,对于下标为i的整数,如果它大于所有它相邻的整数,
或者小于所有它相邻的整数,则称为该整数为一个极值点,极值点的下标就是i。
一次成功!
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int n, k, i,j;
//ifstream cin("data.txt");
while (cin >> n)
{
for (i = 0; i < n; i++)
{
cin >> k;
int num[80], IimitKey[80], count = 0;
for (j = 0; j < k; j++)
cin >> num[j];
//核心算法部分
if (num[0] != num[1])
IimitKey[count++] = 0;
for (j = 1; j < k - 1; j++)
{
if (num[j] < num[j - 1] && num[j] < num[j + 1] || num[j] > num[j - 1] && num[j] > num[j + 1])
IimitKey[count++] = j;
}
if (num[k-1] != num[k-2])
IimitKey[count++] = k-1;
for (j = 0; j < count - 1; j++)
cout << IimitKey[j] << " ";
cout << IimitKey[count - 1] << endl;
}//end of for
}//end of while
//system("pause");
return 0;
}