题目链接:HDU 2008

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

代码

import java.util.*;
class  Main
{
    
    public static void main(String[] args) 
    {
        int  ans1,ans2,ans3,n;
        double t;
        Scanner read=new Scanner(System.in);
        while(read.hasNext()){
            ans1=ans2=ans3=0;
            n=read.nextInt();
            if(n==0)
                break;
            while(n-->0){
                t=read.nextDouble();
                if(t>0)
                    ans1++;
                else if(t==0)
                    ans2++;
                else ans3++;
            }
            System.out.printf("%d %d %d",ans3,ans2,ans1);
            System.out.println();
        }
     }
}