描述 | |
---|---|
知识点 | 函数,指针 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 首先输入一个正整数n, |
输出 | 输出负数的个数,和所有正整数的平均值。 注:输出 当平均值为整数直接输出,如果不为整数保留一小数。 |
样例输入 | 5 1 2 3 4 5 |
样例输出 | 0 3 |
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,neg=0,pos=0,tmp,sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>tmp;
if(tmp<0)
neg++;
else if(tmp>0)
{
sum+=tmp;
pos++;
}
}
cout<<neg<<" ";
if(pos!=0)
{
if(sum%pos==0)
cout<<sum/pos<<endl;
else
cout<<fixed<<showpoint<<setprecision(1)<<float(sum)/pos<<endl;
}
else
cout<<pos<<endl;
//system("pause");
return 0;
}