zoj 1338 Up and Down Sequences

zoj 1338 Up and Down Sequences,第1张

zoj 1338 Up and Down Sequences
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int num[35];int main(){int len,i,n,x,flag,up,upnum,down,downnum,tmp,ff;while( scanf("%d",&n) && n ){len = 1;num[0] = n;while( scanf("%d",&x) && x )num[len++] = x;up = upnum = down = downnum = tmp = 0;ff = flag = 0;for(i=1; i<len; i++){if( num[i] == num[i-1] ){if( !flag && !ff )tmp++; if( flag ) down++;if( ff )up++;}if( num[i] < num[i-1] ){ff = 0;  if( !flag ){flag = 1; downnum++;}down++;down += tmp;  tmp = 0;}if( num[i] > num[i-1] ){flag = 0;if( !ff ){upnum++;ff = 1;}up++;up += tmp;tmp = 0;}}double ansup,ansdown;if( upnum == 0 )  ansup = 0;elseansup = (double)up/upnum;if( downnum == 0 )ansdown = 0;elseansdown = (double)down/downnum;printf("Nr values = %d:  %.6lf %.6lfn",len,ansup,ansdown);}        return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4924825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存