aboutsummaryrefslogtreecommitdiff
path: root/challenge-225/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-07-17 18:07:20 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-07-17 18:07:20 +0800
commit1d3872b50d7fe670c5910388f163da55ded8fa77 (patch)
tree50e95b7831dd9e3155a074b2a41e5fdf905063df /challenge-225/deadmarshal/cpp/ch-1.cpp
parent868de39e9ccd2c5187f4a34e78f5348e86698844 (diff)
parentd4c19914d808b095e1f4832042c5db8c645d0aae (diff)
downloadperlweeklychallenge-club-1d3872b50d7fe670c5910388f163da55ded8fa77.tar.gz
perlweeklychallenge-club-1d3872b50d7fe670c5910388f163da55ded8fa77.tar.bz2
perlweeklychallenge-club-1d3872b50d7fe670c5910388f163da55ded8fa77.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-225/deadmarshal/cpp/ch-1.cpp')
-rw-r--r--challenge-225/deadmarshal/cpp/ch-1.cpp31
1 files changed, 31 insertions, 0 deletions
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<iostream>
+#include<vector>
+#include<cctype>
+
+std::size_t max_words(const std::vector<std::string> &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<std::string>
+ vec{"Perl and Raku belong to the same family.",
+ "I love perl.",
+ "The Perl and Raku Conference."};
+ std::vector<std::string>
+ 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;
+}
+