码迷,mamicode.com
首页 > 其他好文 > 详细

HDU2008-数值统计

时间:2015-08-01 11:23:00      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

描述:

  统计给定的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;
}

 

HDU2008-数值统计

标签:

原文地址:http://www.cnblogs.com/lucio-yr/p/4693812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!