summaryrefslogtreecommitdiff
path: root/1_anno/Programmazione_1/h9_5.cc
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-10-18 18:56:43 +0200
committerSanto Cariotti <dcariotti24@gmail.com>2020-10-20 09:08:52 +0200
commitf279107065146a4940f5e73602a1c3c09e58b31d (patch)
treefd892749637a8b6c5c31ccb80bba04ade76ab87a /1_anno/Programmazione_1/h9_5.cc
parent4e063e32250312c38d5646840719b62429362b21 (diff)
chore: name of first year folder
Diffstat (limited to '1_anno/Programmazione_1/h9_5.cc')
-rw-r--r--1_anno/Programmazione_1/h9_5.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/1_anno/Programmazione_1/h9_5.cc b/1_anno/Programmazione_1/h9_5.cc
new file mode 100644
index 0000000..a2e3f8b
--- /dev/null
+++ b/1_anno/Programmazione_1/h9_5.cc
@@ -0,0 +1,51 @@
+#include <iostream>
+#include <algorithm>
+#include <map>
+
+// Date due matrici e un numero p, stampare i valori che compaiono p volte dalla prima alla seconda matrice
+
+int main() {
+ const auto N{4}, M{4}, L{4}, Q{4}, p{4};
+ int V[N][M] = {
+ {3, 1, 5, 50},
+ {5, 3, 1, 5},
+ {8, 7, 4, 5},
+ {4, 7, 4, 5},
+ };
+
+ int W[L][Q] = {
+ {30, 3, 5, 50},
+ {51, 25, 12, 5},
+ {90, 12, 4, 5},
+ {4, 6, 4, -3},
+ };
+
+ std::map<int, int> values;
+
+ for(auto i = 0; i < N; ++i) {
+ for(auto j = 0; j < M; ++j) {
+ if(values.find(V[i][j]) == values.end())
+ values.insert({V[i][j], 1});
+ else
+ values[V[i][j]] += 1;
+ }
+ }
+
+ for(auto i = 0; i < L; ++i) {
+ for(auto j = 0; j < Q; ++j) {
+ auto elem = values.find(W[i][j]);
+ if(elem != values.end()) {
+ if(elem->second >= p) {
+ std::cout << W[i][j] << ' ';
+ } else {
+ std::cout << "x ";
+ }
+ } else {
+ std::cout << "x ";
+ }
+ }
+ std::cout << '\n';
+ }
+
+ return 0;
+}