diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
commit | d2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch) | |
tree | a51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /Year_1/Programming_1/ex12.cc | |
parent | 98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff) |
conf: rename
Diffstat (limited to 'Year_1/Programming_1/ex12.cc')
-rw-r--r-- | Year_1/Programming_1/ex12.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Year_1/Programming_1/ex12.cc b/Year_1/Programming_1/ex12.cc new file mode 100644 index 0000000..ab20cef --- /dev/null +++ b/Year_1/Programming_1/ex12.cc @@ -0,0 +1,50 @@ +#include <iostream> +#include <vector> +#define N 3 +using namespace std; + +string* func(string a[N][N], short k, string s) { + string* sn = new string[N]; + vector<string> l; + + // Diagonale secondaria + for(int i = N-1, j = 0; i >= 0; --i, ++j) { + l.push_back(a[i][j]); + } + + bool d2 = true; + for(auto const& i : l) { + if(i.length() < k || i.find(s) != 0) { + d2 = false; + break; + } + } + + if(d2) { + for(int i = 0; i < N; ++i) { + sn[i] = l.at(i); + } + } else { + for(int i = 0; i < N; ++i) { + sn[i] = a[i][i]; + } + } + + return sn; +} + +int main() { + string a[N][N] = { + {"aab", "bbc", "4de"}, + {"xyb", "bbc", "yz3"}, + {"47x", "1y_", "23g"}, + }; + string* x = func(a, 1, "4"); + + for(int i = 0; i < N; ++i) + cout << x[i] << ' '; + + cout << endl; + + return 0; +} |