summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/ex1_23_04_19.cc
blob: c977ece863bb2804dc089374c871ac4564613f1c (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
#include<iostream>
#define N 4
#define M 3

using namespace std;

double func(string (*S)[M], string s1, short k) {
    if(k < 1 || k > M) return -1;

    short counter{};
    short c_strings{};

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < k; ++j) {
            ++c_strings;
            if(S[i][j].length() > s1.length())
                ++counter;
        }
    }
    
    return static_cast<double>(counter*100/c_strings);
}

int main() {
    string A[N][M] = {
        {"red", "orange", "green"},
        {"red", "orange", "green"},
        {"red", "orange", "green"},
        {"red", "orange", "green"},
    };

    cout << func(&A[0], "pink", 2);
   
    return 0;
}