HDU2008-数值统计

描述:

  统计给定的n个实数中,负数、零和正数的个数。

代码:

  

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include <math.h>
using namespace std;
#define N 200
int main(){
    int n,neg,pos,zero;
    double temp;
    while ( scanf("%d",&n) && n!=0 ){
        neg=pos=zero=0;
        for( int i=0;i<n;i++ ){
            scanf("%lf",&temp);
            if( temp==0 )
                zero+=1;
            else if( temp<0 )
                neg+=1;
            else if( temp>0 )
                pos+=1;
        }
        cout<<neg<<" "<<zero<<" "<<pos<<endl;
    }
    system("pause");
    return 0;
}

 

posted @ 2015-08-01 11:00  Lucio.Yang  阅读(273)  评论(0编辑  收藏  举报