diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
commit | d2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch) | |
tree | a51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /Year_1/Programming_1/ex13.cc | |
parent | 98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff) |
conf: rename
Diffstat (limited to 'Year_1/Programming_1/ex13.cc')
-rw-r--r-- | Year_1/Programming_1/ex13.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Year_1/Programming_1/ex13.cc b/Year_1/Programming_1/ex13.cc new file mode 100644 index 0000000..f9f19fa --- /dev/null +++ b/Year_1/Programming_1/ex13.cc @@ -0,0 +1,45 @@ +#include <iostream> +#include <memory> +#include <algorithm> +#include <vector> +using namespace std; + +template<int N, int K> +unique_ptr<double[]> func(int (&A)[K][N], int (&B)[N][K]) { + auto arr = unique_ptr<double[]>(new double{K}); + for(int i = 0; i < K; ++i) { + vector<int> t; + int sum = 0; + for(int j = 0; j < N; ++j) { + t.push_back(B[j][i]); + sum+=A[i][j]; + } + + double media = static_cast<double>(sum)/N; + auto min_num = min_element(begin(t), end(t)); + arr[i] = media - *min_num; + } + + return arr; +} + +int main() { + const int N2 = 3, K2 = 2; + int A[K2][N2] = { + {3, 7, 10}, + {5, 12, 32}, + }; + int B[N2][K2] = { + {12, 10}, + {15, 17}, + {8, 0}, + }; + auto x = func(A, B); + + for(int i = 0; i < K2; ++i) + cout << x[i] << ' '; + + cout << endl; + + return 0; +} |