Solutions
This commit is contained in:
parent
79b9099274
commit
d3aa42a3e0
64 changed files with 2726 additions and 0 deletions
36
sheet1/B/means.cpp
Normal file
36
sheet1/B/means.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void means(int a, int b, int c, double &ar, double &ge, double &ha) {
|
||||
ar = (a+b+c) / 3.0;
|
||||
|
||||
|
||||
ge = pow(a,1.0/3.0) * pow(b,1.0/3.0) * pow(c,1.0/3.0); //do it instead of pow(a*b*c,1.0/3.0) to prevent integer overflow
|
||||
|
||||
ha = 3.0 / (1.0/a +1.0/b +1.0/c);
|
||||
}
|
||||
|
||||
void means_vector(const vector<short> &input, double &ar, double &ge, double &ha) {
|
||||
int size = input.size();
|
||||
|
||||
if (size == 0) {
|
||||
cout << "Empty input" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
ar = 0;
|
||||
ge = 1;
|
||||
ha = 0;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
ar += input.at(i);
|
||||
ge *= pow(input.at(i), 1.0 / size);
|
||||
ha += 1.0 / input.at(i);
|
||||
}
|
||||
|
||||
ar /= size;
|
||||
ha = size / ha;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue