summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_1/ex1_04_12_19.cc
blob: 3d352f142d153d24350761ce918cc9bedaeee0bb (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
#include <iostream>

using namespace std;

template<int N, int M>
short func(int (&A)[N][M], double d1, double d2, short s) {
    short result{0};

    for(int i = 0; i < M; ++i) {
        short temp_result{0};
        for(int j = 0; j < N-1; ++j) {
            if(temp_result >= s)
                continue;

            double div = static_cast<double>(A[j][i]) / static_cast<double>(A[j+1][i]);
            if(div >= d1 && div <= d2)
                temp_result++;
        }

        if(temp_result >= s)
            result++;
    }

    return result;
}

int main() {
    int a1[5][2] = {
        {15, 100},
        {15, 100},
        {10, 100},
        {10, 10},
        {10, 30},
    };  

    cout << func(a1, 0.3, 1.9, 2) << endl;

    return 0;
}