zoukankan      html  css  js  c++  java
  • 练习2 G题

     
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
     

    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
     
     
    #include <stdio.h>
    int main()
    {
        int m,i;
        double n;
        while(scanf("%d",&m))
        {
            if(m == 0)
                break;
            int a = 0, b = 0, c = 0;
            for (i = 0; i < m; i++)
            {
                scanf("%lf",&n);
                if(n < 0)
                    a++;
                if(n > 0)
                    c++;
                else b++;
            }
            printf("%d %d %d
    ",a,b,c);
        }
        return 0;
    }
     
  • 相关阅读:
    树的可视化
    图的可视化
    1+1=2
    用xapian来做索引
    学习的快乐
    项目小结
    z=sin(xy)
    Min Stack
    互联网公司的文化
    为什么要读数学书
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4905330.html
Copyright © 2011-2022 走看看