|
发表于 2022-3-13 21:01:45
|
显示全部楼层
题目已经提示非常清楚了,我写了 C++,至於 C 可以的话,试试自己做吧:- #include <iostream>
- #include <algorithm>
- #include <sstream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <cmath>
- auto min = [](std::vector<int> V) -> int
- { return *std::min_element(V.begin(), V.end()); };
- auto max = [](std::vector<int> V) -> int
- { return *std::max_element(V.begin(), V.end()); };
- double avg(std::vector<int> V) {
- double res = 0;
- for (int x : V) res += x;
- return res / static_cast<double> (V.size());
- }
- double MSE(std::vector<int> V) {
- double a = avg(V);
- double res = 0;
- for (int x : V) res += (x - a) * (x - a);
- return sqrt(res / static_cast<double> (V.size()));
- }
- int main() {
- std::string str;
- std::getline(std::cin, str);
- std::stringstream ss(str);
- auto start = std::istream_iterator<int>{ ss };
- auto end = std::istream_iterator<int>{};
- std::vector<int> score(start, end);
- std::cout
- << min(score) << " " // 最小值
- << max(score) << " " // 最大值
- << std::fixed
- << std::setprecision(1)
- << avg(score) << " " // 平均值
- << std::setprecision(2)
- << MSE(score) // 均方差
- << std::endl;
- return 0;
- }
复制代码- 80 82 84 86
- 80 86 83.0 2.24
- 82 82 83 85
- 82 85 83.0 1.22
复制代码 |
|