题解 | #记负均正II#
记负均正II
http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
int a;
vector<int>b;
while(cin>>a)
{
b.push_back(a);
}
int c=0;
double d=0;
for(int i=0;i<b.size();i++)
{
if(b[i]<0)
{
c++;
}
else
{
d+=b[i];
}
}
if(b.size()!=c)
{
d=d/(b.size()-c);
}
cout<<c<<endl;
cout<<fixed<<setprecision(1)<<d;
return(0);
}
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
int a;
vector<int>b;
while(cin>>a)
{
b.push_back(a);
}
int c=0;
double d=0;
for(int i=0;i<b.size();i++)
{
if(b[i]<0)
{
c++;
}
else
{
d+=b[i];
}
}
if(b.size()!=c)
{
d=d/(b.size()-c);
}
cout<<c<<endl;
cout<<fixed<<setprecision(1)<<d;
return(0);
}