From 9c11fababb9b6b194e646fbeb62d141aacf74c43 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 25 May 2024 16:08:17 +0300 Subject: [w13] Added solutions --- week13/Exercise1/WordString.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 week13/Exercise1/WordString.cpp (limited to 'week13/Exercise1/WordString.cpp') diff --git a/week13/Exercise1/WordString.cpp b/week13/Exercise1/WordString.cpp new file mode 100644 index 0000000..4ba3cca --- /dev/null +++ b/week13/Exercise1/WordString.cpp @@ -0,0 +1,25 @@ +#include "WordString.h" + +bool isBlank(char ch) { + return ch == ' ' || ch == '\n' || ch == '\t'; +} + +WordString::WordString(const char* str) : String(str), IndexArray() { + this->size = 1; + for (int i = 1; str[i] != '\0'; i++) { + if (isBlank(str[i - 1]) && !isBlank(str[i])) { + this->size++; + } + } + + this->indecies = new int[this->size]; + + this->indecies[0] = 0; + unsigned indeciesI = 1; + + for (int i = 1; str[i] != '\0'; i++) { + if (isBlank(str[i - 1]) && !isBlank(str[i])) { + indecies[indeciesI++] = i; + } + } +} -- cgit v1.2.3