64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int main()
{
int a[14] = {9,3, 1,4,5, 3, 2, 4, 6, 8, 10, 3, 7, 11};
int n = 14;
int i = 0, j = 0;
int gu, feng, boju, minboju = 0;
while (true)
{
while (a[i+1] <= a[i] && i<n-1)
++i;
//cout << i << " " << a[i] << endl;
j = i;
while (a[j+1] >= a[j] && j<n-1)
++j;
//cout << j << " " << a[j] << endl;
boju = a[j] - a[i];
if (boju > minboju)
{
minboju = boju;
gu = i;
feng = j;
}
if (j==n-1)
break;
i = j;
}
cout << gu+1 << ":" << a[gu] << endl;
cout << feng+1 << ":" << a[feng] << endl;
return 0;
}