数值统计Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 150413 Accepted Submission(s): 71277 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
|
c语言如下:
#include<stdio.h>
int main()
{
int n;
double x;
while((scanf("%d",&n)!=EOF))
{
int a=0,b=0,c=0;
if(n==0)
{
break;
}
while(n)
{
scanf("%lf",&x);
if(x<0)
{
a++;
n=n-1;
}
else if(x==0)
{
b++;
n=n-1;
}
else if(x>0)
{
c++;
n=n-1;
}
}
printf("%d %d %d\n",a,b,c);
}
return 0;
}
c++如下:
#include<iostream>
using namespace std;
int main()
{
int n;
double a,b,c,d;
while(cin>>n&&n!=0&&n<100)
{
a=b=c=0;
for(int i=0;i<n;i++)
{
cin>>d;
if(d<0)
a++;
else if(d==0)
b++;
else
c++;
}
cout<<a<<" "<<b<<" "<<c<<endl;
}
return 0;
}