summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/h9_5.cc
blob: a2e3f8bf98985460e39f45f75cc7b787fe4547fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}