0
点赞
收藏
分享

微信扫一扫

(hdu 简单题 128道)hdu 2008 数值统计(统计一列数中正数、负数、0的个数)


题目:


数值统计

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 66745    Accepted Submission(s): 33573


Problem Description

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

 


Input

输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。

 


Output

对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。

 


Sample Input

6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0

 


Sample Output

1 2 3
0 0 5

 


Author

lcy

 


Source

C语言程序设计练习(二)

 


Recommend

JGShining   |   We have carefully selected several similar problems for you:   2009  2010  2002  2011  2000 

 



题目分析:

                简单题。



代码如下:


/*
 * h.cpp
 *
 *  Created on: 2015年3月20日
 *      Author: Administrator
 *      
 *      hdu 2008
 */


#include <iostream>
#include <cstdio>

using namespace std;


int main(){
	int n;
	while(scanf("%d",&n)!=EOF,n){
		int zero_num = 0;
		int negaive_num = 0;
		int positive_num = 0;

		int i;
		double temp;
		for(i = 0 ; i < n ; ++i){
			scanf("%lf",&temp);

			if(temp == 0){
				zero_num++;
			}else if(temp < 0){
				negaive_num++;
			}else{
				positive_num++;
			}
		}

		printf("%d %d %d\n",negaive_num,zero_num,positive_num);
	}

	return 0;
}





举报

相关推荐

0 条评论