From 5e2d33632ed1dfc689f14ebf1a782239411d8534 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 5 Jan 2024 08:17:59 +0200 Subject: [w9] Added solutions for first 3 exercises --- week09/ex3.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 week09/ex3.cpp (limited to 'week09/ex3.cpp') diff --git a/week09/ex3.cpp b/week09/ex3.cpp new file mode 100644 index 0000000..6baae4f --- /dev/null +++ b/week09/ex3.cpp @@ -0,0 +1,26 @@ +#include +#include + +bool isSkippable(char c) { + return c == ' ' || c == '.' || c == ',' || c == '!' || c == '?'; +} + +int main() { + char str[1025]; + std::cin.getline(str, 1025); + + size_t strSize = strlen(str); + int words = 1; + bool lastWasSkippable = false; + for (int i = 0; i < strSize; i++) { + if (!isSkippable(str[i]) && lastWasSkippable) { + words++; + lastWasSkippable = false; + } + else if (isSkippable(str[i])) { + lastWasSkippable = true; + } + } + + std::cout << words << std::endl; +} -- cgit v1.2.3