summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/ex17.cc
blob: 9eee61dc69cfcafad93ee86758bb4815edd8d737 (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
#include <iostream>

using namespace std; 

template<int N, int M>
short* func(string (&S)[N][M], char (&C)[N], char (&D)[N]) {
    short* a = new short[N];

    for(int i = 0; i < N; ++i) {
        short counter = 0;
        for(auto const& rows_string : S[i]) {
            if(rows_string.length() > 2) {
                if(rows_string.at(0) == C[i]
                    && rows_string.at(rows_string.length()-1) == D[i])
                        ++counter;
            }
        }

        a[i] = counter;
    }    


    return a;
}

int main() {
    string t[3][3]{
        {"suca", "we", "soia"},
        {"omg", "ooohygodg", "onopg"},
        {"", "mii", ""},
    };

    char c[3] = {'s', 'o', 'a'};
    char d[3] = {'a', 'g', 'a'};

    short* n = func(t, c, d);

    for(int i = 0; i < 3; ++i) {
        cout << n[i] << ' ';
    }

    return 0;
}