summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_1/ex2_27_01_20.cc
blob: 25caf5b638c26d0a6206391ba8ea735631f4ddd3 (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
52
53
54
55
56
57
#include<iostream>
#include<set>

using namespace std;

template<int N, int M>
double func(string (&A)[N][M], string x, string y, short k, short w) {
    set<char> s;
    for(char const&c : x) s.insert(c);
    x = "";
    for(char const&c: s) x+=c;

    s.clear();
    for(char const&c : y) s.insert(c);
    y = "";
    for(char const&c: s) y+=c;

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < M; ++j) {
            s.clear();
            for(char const&c : A[i][j]) s.insert(c);
            A[i][j] = "";
            for(char const&c: s) A[i][j]+=c;
        }
    }

    short counter{};
    for(int i = 0; i < M; ++i) {
        short k_i{};
        for(int j = 0; j < N; ++j) {
            if(A[j][i].length() < w) continue;
            short char_counter{};
            for(char const& c: A[j][i]) {
                if(x.find(c) != std::string::npos && y.find(c) != std::string::npos)
                    ++char_counter;
            }
            if(char_counter >= w)
                ++k_i;
        }
        if(k_i >= k)
            ++counter;
    }

    return static_cast<double>(counter*100)/static_cast<double>(M);
}

int main() {
    string A[3][4] = {
        {"we,", "heila", "ciaone", ""},
        {"we,", "heila", "ciaone", ""},
        {"we,", "heila", "ciaone", ""},
    };

    cout << func(A, "we", "we", 2, 2);    

    return 0;
}