#include "iostream"
#include "stdio.h"
#include "iomanip"
using namespace std;
int main()
{
int num[30], len, i, uptimes, downtimes, midtimes, sum1, sum2;
bool up, down;
while (cin >> num[0] && num[0])
{
len = 1;
while (cin >> num[len] && num[len])
len++;
up = false, down = false;
uptimes = downtimes = midtimes = sum1 = sum2 = 0;
for (i = 1; i < len; i++)
{
if (up && num[i] >= num[i-1])
sum1++;
else if (down && num[i] <= num[i-1])
sum2++;
else if (up && num[i] < num[i-1])
{
up = false;
down = true;
downtimes++;
sum2++;
}
else if (down && num[i] > num[i-1])
{
down = false;
up = true;
uptimes++;
sum1++;
}
else if (!up && !down && num[i] > num[i-1])
{
up = true;
sum1 += midtimes;
midtimes = 0;
sum1++;
uptimes++;
}
else if (!up && !down && num[i] < num[i-1])
{
down = true;
sum2 += midtimes;
midtimes = 0;
sum2++;
downtimes++;
}
else if (!up && !down && num[i] == num[i-1])
midtimes++;
}
cout.setf(ios::fixed);
cout << "Nr values = " << len << ": ";
if (uptimes == 0)
cout << "0.000000 ";
else
cout << setprecision(6) << double(sum1) / double (uptimes) << " ";
if (downtimes == 0)
cout << "0.000000" << endl;
else
cout << setprecision(6) << sum2 / (double)downtimes << endl;
}
}
zoj 1338 Up and Down Sequences
最新推荐文章于 2024-11-13 18:16:44 发布