aboutsummaryrefslogtreecommitdiff
path: root/week09/ex3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week09/ex3.cpp')
-rw-r--r--week09/ex3.cpp26
1 files changed, 26 insertions, 0 deletions
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 <iostream>
+#include <cstring>
+
+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;
+}