From 2a9c7f49feef90d54aa477b5a80c2979a548cb81 Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Sat, 11 Mar 2023 17:03:30 +0330 Subject: TWC207 --- challenge-207/deadmarshal/cpp/ch-1.cpp | 33 +++++++++++++++++++++++++++++++++ challenge-207/deadmarshal/cpp/ch-2.cpp | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 challenge-207/deadmarshal/cpp/ch-1.cpp create mode 100644 challenge-207/deadmarshal/cpp/ch-2.cpp (limited to 'challenge-207/deadmarshal/cpp') diff --git a/challenge-207/deadmarshal/cpp/ch-1.cpp b/challenge-207/deadmarshal/cpp/ch-1.cpp new file mode 100644 index 0000000000..e778f5824b --- /dev/null +++ b/challenge-207/deadmarshal/cpp/ch-1.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +bool all_match(const std::string &s1, const std::string &s2) +{ + for(auto &c : s1) if(s2.find(c) == std::string::npos) return false; + return true; +} + +void keyboard_word(std::vector &vec) +{ + const std::vector + qwerty{"qwertyuiop","asdfghjkl","zxcvbnm"}; + for(auto &s : vec) + std::transform(s.begin(),s.end(),s.begin(), + [](unsigned char c){return std::tolower(c);}); + for(const auto &q : qwerty) + for(const auto &s : vec) + if(all_match(s,q)) std::cout << s << ' '; + std::cout << '\n'; +} + +int main() +{ + std::vector vec1{"Hello","Alaska","Dad","Peace"}, + vec2{"OMG","Bye"}; + keyboard_word(vec1); + keyboard_word(vec2); + return 0; +} + diff --git a/challenge-207/deadmarshal/cpp/ch-2.cpp b/challenge-207/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..6af3160443 --- /dev/null +++ b/challenge-207/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,22 @@ +#include +#include + +int h_index(const std::vector &vec) +{ + int ret{}; + for(int i = 0; i < vec.size(); ++i) + if(i >= vec[i]) + { + ret = i; + break; + } + return ret; +} + +int main() +{ + std::cout << h_index({10,8,5,4,3}) << '\n'; + std::cout << h_index({25,8,5,3,3}) << '\n'; + return 0; +} + -- cgit