summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/ex15.cc
blob: 525882c60cb4be64018be8d00c8bbdf9eb974cee (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
#include <iostream>
using namespace std;

template<int N, int M>
unique_ptr<string[]> func(string (&A)[N][M], short (&B)[N][M]) {
    auto arr = unique_ptr<string[]>(new string[N]);

    for(int i = 0; i < N; ++i) {
        short sum{0};
        string tmp{""};
        for(int j = 0; j < M; ++j) {
            sum+=B[i][j];
            tmp+=A[i][j];
        }

        arr[i] = tmp.length() >= sum ? tmp : "";
    }

    return arr;
}

int main() {
    string A[2][3] = {
        {"aab", "aA", "314"},
        {"1334", "5715", "__"},
    };

    short B[2][3] = {
        {2, 3, 0},
        {1, 15, 7}
    };
    
    auto x = func(A, B);

    for(int i = 0; i < 2; ++i)
        cout << x[i] << ' ';
    
    cout << endl;

    return 0;
}