From 272a93422300e09882e9e56c18b08604f3bb77a7 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 27 Jan 2020 11:20:41 +0100 Subject: ex 27/1/20 --- I_anno/Programmazione_1/ex2_27_01_20.cc | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 I_anno/Programmazione_1/ex2_27_01_20.cc (limited to 'I_anno/Programmazione_1') diff --git a/I_anno/Programmazione_1/ex2_27_01_20.cc b/I_anno/Programmazione_1/ex2_27_01_20.cc new file mode 100644 index 0000000..25caf5b --- /dev/null +++ b/I_anno/Programmazione_1/ex2_27_01_20.cc @@ -0,0 +1,57 @@ +#include +#include + +using namespace std; + +template +double func(string (&A)[N][M], string x, string y, short k, short w) { + set s; + for(char const&c : x) s.insert(c); + x = ""; + for(char const&c: s) x+=c; + + s.clear(); + for(char const&c : y) s.insert(c); + y = ""; + for(char const&c: s) y+=c; + + for(int i = 0; i < N; ++i) { + for(int j = 0; j < M; ++j) { + s.clear(); + for(char const&c : A[i][j]) s.insert(c); + A[i][j] = ""; + for(char const&c: s) A[i][j]+=c; + } + } + + short counter{}; + for(int i = 0; i < M; ++i) { + short k_i{}; + for(int j = 0; j < N; ++j) { + if(A[j][i].length() < w) continue; + short char_counter{}; + for(char const& c: A[j][i]) { + if(x.find(c) != std::string::npos && y.find(c) != std::string::npos) + ++char_counter; + } + if(char_counter >= w) + ++k_i; + } + if(k_i >= k) + ++counter; + } + + return static_cast(counter*100)/static_cast(M); +} + +int main() { + string A[3][4] = { + {"we,", "heila", "ciaone", ""}, + {"we,", "heila", "ciaone", ""}, + {"we,", "heila", "ciaone", ""}, + }; + + cout << func(A, "we", "we", 2, 2); + + return 0; +} -- cgit v1.2.3-18-g5258