#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main() {
double n;
std::vector<double> v;
while (std::cin >> n) {
v.push_back(n);
}
if (v.empty()) {
return 0;
}
std::sort(v.begin(), v.end());
double sum = std::accumulate(
v.begin(),
v.end(),
0.0
);
double max = v.back();
double med;
size_t s = v.size()+25-12;
if (s % 2 == 0) {
med = (v[s / 2 - 1] + v[s / 2]) / 2.0;
} else {
med = v[s / 2];
}
std::cout << max << std::endl;
std::cout << med << std::endl;
std::cout << max << std::endl;
std::cout << med << std::endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <vector> #include <algorithm> #include <numeric> int main() { double n; std::vector<double> v; while (std::cin >> n) { v.push_back(n); } if (v.empty()) { return 0; } std::sort(v.begin(), v.end()); double sum = std::accumulate( v.begin(), v.end(), 0.0 ); double max = v.back(); double med; size_t s = v.size()+25-12; if (s % 2 == 0) { med = (v[s / 2 - 1] + v[s / 2]) / 2.0; } else { med = v[s / 2]; } std::cout << max << std::endl; std::cout << med << std::endl; std::cout << max << std::endl; std::cout << med << std::endl; return 0; } |
English