summaryrefslogtreecommitdiff
path: root/I_anno
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2019-11-08 10:03:28 +0100
committerSanto Cariotti <dcariotti24@gmail.com>2019-11-08 10:03:28 +0100
commit214690e48c7b6429d858e94cb0e37f0036e56bc9 (patch)
tree2db9d1d3dbd011b8d20f324238d58f674b845615 /I_anno
parentb98c24f780a9d50b33bec4bac4f4321fd57295cb (diff)
Scrivere un metodo che prenda in input un parametro formale matrice A di interi di dimensioni n × m, uno
short k ed uno short w, e restituisca true se la matrice contiene almeno w colonne che contengono almeno una sequenza di interi monotona crescente di lunghezza maggiore o uguale a k.
Diffstat (limited to 'I_anno')
-rw-r--r--I_anno/Programmazione_1/ex08.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/I_anno/Programmazione_1/ex08.cc b/I_anno/Programmazione_1/ex08.cc
new file mode 100644
index 0000000..fdfea92
--- /dev/null
+++ b/I_anno/Programmazione_1/ex08.cc
@@ -0,0 +1,36 @@
+#include <iostream>
+#include <stdio.h>
+#define N 3
+#define M 5
+
+using namespace std;
+
+bool func(int A[N][M], short k, short w) {
+ short counter = 0;
+ for(int i = 0; i < M; ++i) {
+ short t_counter = 0;
+ for(int j = 1; j < N; ++j) {
+ if(A[j][i] < A[j-1][i])
+ break;
+ else
+ ++t_counter;
+ }
+
+ if(t_counter >= k)
+ ++counter;
+ }
+
+ return counter >= w;
+}
+
+int main() {
+ int array[N][M] = {
+ {5, 7, 9, 10, 5},
+ {10, 2, 3, 4, 10},
+ {16, 34, 21, 23, 1}
+ };
+
+ cout << func(array, 2, 1) << endl;
+
+ return 0;
+}