两个运行结果:
输入1:5
1 2 5 3 5
输出:2
输入:6
1 2 3 4 5 6
输出:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n=0;
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int s = 0;
int* m = new int[n]();
m[0] = a[0];
int min = m[0];
for (int i = 0; i < n; i++)//求
{
if (a[i] < min)
min = a[i];
m[i] = min;
//cout <<setw(2)<< m[i];
}
int* M = new int[n]();
M[n - 1] = a[n - 1];
int max = a[n - 1];
for (int i = n - 1; i >= 0; i--)
{
if (a[i] > max)
max = a[i];
M[i] = max;
//cout << setw(2) << M[i];
}
for (int i = 1; i < n-1; i++)
{
if (m[i] < a[i] && a[i] < M[i])
s++;
}
cout << s;
delete[]a;
delete[]m;
delete[]M;
return 0;
}