水题,直接贴代码。
//poj 1492
//sep9
#include <iostream>
using namespace std;
int a[64];
int n;
void deal()
{int up=0,down=0,upSum=0,downSum=0; int i,j;for(i=1;i<n;){if(a[i]<a[i+1]){++up;for(j=i+1;j<=n;++j)if(a[j-1]<=a[j])++upSum;elsebreak;}if(a[i]>a[i+1]){++down;for(j=i+1;j<=n;++j)if(a[j-1]>=a[j])++downSum;elsebreak; }if(a[i]==a[i+1]){int flag=0;for(j=i+1;j<=n;++j)if(a[j-1]<a[j]){flag=1;break;}else if(a[j-1]>a[j]){flag=-1;break;}if(flag==0)break;if(flag==1){++up;for(j=i+1;j<=n;++j)if(a[j-1]<=a[j])++upSum;elsebreak; }if(flag==-1){++down;for(j=i+1;j<=n;++j)if(a[j-1]>=a[j])++downSum;elsebreak; }}i=j-1;}double f1,f2;if(upSum==0)f1=0;elsef1=upSum*1.0/up;if(downSum==0)f2=0;elsef2=downSum*1.0/down; printf("Nr values = %d: %.6lf %.6lf\n",n,f1,f2);
}int main()
{n=0;while(1){int x;scanf("%d",&x);if(x==0){if(n==0)break;deal();n=0;}elsea[++n]=x;}return 0;
}