杭电ACM2008数值统计

数值统计

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


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
 
 1 import java.util.Scanner;
 2 public class Main{
 3     public static void main(String[] args) {
 4         Scanner scan = new Scanner(System.in);
 5         int n=0;
 6         int a,b,c;
 7         double m = 0.0;
 8         while((n=scan.nextInt())!=0){
 9             a = 0;
10             b = 0;
11             c = 0;
12             for(int i =1;i<=n;i++){
13                 m = scan.nextDouble();
14                 if(m<0)
15                     a++;
16                 else if(m==0)
17                     b++;
18                 else 
19                     c++;
20             }
21             System.out.print(a);
22             System.out.print(" ");
23             System.out.print(b);
24             System.out.print(" ");
25             System.out.println(c);
26         }
27     }
28 }
原文地址:https://www.cnblogs.com/bchxsx322/p/2467811.html