排序、得到最大值、最小值、平均值
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
std::vector<float> v{ 0.200000, 0.200000, 0.100000, 0.200000, 0.200000, 0.200000, 0.200000, 0.200000, 0.200000, 0.200000, 0.200000, 0.100000 };
std::sort(v.begin(), v.end());
std::cout << "min:" << *min_element(v.begin(), v.end()) << std::endl;
std::cout << "max:" << *max_element(v.begin(), v.end()) << std::endl;
std::cout << "sum:" << accumulate(v.begin(), v.end(), 0.000000) << std::endl;
std::cout << "aver:" << accumulate(v.begin(), v.end(), 0.000000) / v.size() << std::endl;
return 0;
}
输出
min:0.1
max:0.2
sum:2.2
aver:0.183333