Problem 2008

来源:互联网 发布:汽车零部件数据库 编辑:程序博客网 时间:2024/04/30 05:01

数值统计

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


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

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

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

Sample Input
6 0 1 2 3 -1 05 1 2 3 4 0.50
 

Sample Output
1 2 30 0 5=====================================================================================================================================感觉没什么好的收获,但是还是在这里卡住了。就是因为输入的那几个数可以是实数,然后交上去就是output limit exceed。因为输入浮点数时会不停的出现数字。
#include <stdio.h>int main(){    int n,i;    double temp;    while (scanf("%d",&n) != EOF && n != 0){        int a=0,b=0,c=0;        for (i=1;i<=n;i++){            scanf("%lf",&temp);            if (temp != 0){                if (temp > 0) a++;                else c++;            }            else b++;        }        printf("%d %d %d\n",c,b,a);    }    return 0;}


0 0
原创粉丝点击