题解 | #记负均正II#
记负均正II
http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int a;
vector<int> vp,vn;
while(cin>>a) {
if(a >= 0)
vp.emplace_back(a);
if(a < 0)
vn.emplace_back(a);
}
cout << vn.size() <<endl;
if(vp.empty() == 1)
printf("0.0");
else {
int sum = 0;;
auto itr = vp.begin();
while(itr!=vp.end())
{
sum += *itr;
++itr;
}
printf("%0.1f", sum*1.0/(int)vp.size());
}
return 0;
}
查看6道真题和解析