From fcd352576e64dd7156578f626b5e91f9dbd41438 Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Fri, 14 Jul 2023 08:12:41 +0330 Subject: TWC225 --- challenge-225/deadmarshal/cpp/ch-1.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-225/deadmarshal/cpp/ch-1.cpp (limited to 'challenge-225/deadmarshal/cpp/ch-1.cpp') diff --git a/challenge-225/deadmarshal/cpp/ch-1.cpp b/challenge-225/deadmarshal/cpp/ch-1.cpp new file mode 100644 index 0000000000..17fb182b49 --- /dev/null +++ b/challenge-225/deadmarshal/cpp/ch-1.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +std::size_t max_words(const std::vector &vec) +{ + size_t count{},max{}; + for(const auto & s : vec) + { + for(const auto &c : s) if(isspace(c)) count++; + if(max < count) max = count; + count = 0; + } + return max+1; +} + +int main(int argc, char **argv) +{ + std::vector + vec{"Perl and Raku belong to the same family.", + "I love perl.", + "The Perl and Raku Conference."}; + std::vector + vec2{"The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."}; + std::cout << max_words(vec) << '\n'; + std::cout << max_words(vec2) << '\n'; + return 0; +} + -- cgit