summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/h9_4.cc
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
commitd2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch)
treea51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /Year_1/Programming_1/h9_4.cc
parent98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff)
conf: rename
Diffstat (limited to 'Year_1/Programming_1/h9_4.cc')
-rw-r--r--Year_1/Programming_1/h9_4.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/Year_1/Programming_1/h9_4.cc b/Year_1/Programming_1/h9_4.cc
new file mode 100644
index 0000000..cd534b3
--- /dev/null
+++ b/Year_1/Programming_1/h9_4.cc
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <algorithm>
+
+// Data matrice V di NxM, array A e numero w<M, trovare se c'è almeno una riga di V con almeno w elementi maggiori di ogni elemento di A
+
+const auto N{4}, M{4}, k{3}, w{2};
+
+bool row_alg(int V[N][M], int* A, int w) {
+ // È ovvio che sia presente almeno 0 elementi, quindi non ha senso continuare
+ if(w <= 0) return true;
+ auto max_element_of_A = std::max_element(A,A+k);
+
+ for(auto i = 0; i < N; ++i) {
+ int counts = 0;
+ for(auto j = 0; j < M; ++j) {
+ if(V[i][j] > *max_element_of_A)
+ counts++;
+
+ if(counts == w)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int main() {
+ int V[N][M] = {
+ {3, 59, 5, 54},
+ {5, 3, 1, 5},
+ {8, 7, 4, 5},
+ {4, 7, 4, 5},
+ };
+
+ int A[k] = {4, 50, 2};
+
+ std::cout << row_alg(V, A, w) << std::endl;
+
+ return 0;
+}