水題,直接貼代碼。
//poj 1492 //sep9 #includeusing 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 =a[j]) ++downSum; else break; } 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; } if(flag==0) break; if(flag==1){ ++up; for(j=i+1;j<=n;++j) if(a[j-1]<=a[j]) ++upSum; else break; } if(flag==-1){ ++down; for(j=i+1;j<=n;++j) if(a[j-1]>=a[j]) ++downSum; else break; } } i=j-1; } double f1,f2; if(upSum==0) f1=0; else f1=upSum*1.0/up; if(downSum==0) f2=0; else f2=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; } else a[++n]=x; } return 0; }