From 7a791e5c464bc01203d8d793f1910917856da236 Mon Sep 17 00:00:00 2001 From: Ilya Volchenkov Date: Wed, 23 Jul 2025 19:14:29 +0300 Subject: [PATCH] 3330 solved --- 3330/3330.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 3330/3330.cpp diff --git a/3330/3330.cpp b/3330/3330.cpp new file mode 100644 index 0000000..a95066f --- /dev/null +++ b/3330/3330.cpp @@ -0,0 +1,59 @@ +#include + +namespace { + class Solution { + public: + int possibleStringCount(std::string word) { + const size_t word_length = word.length(); + if (word_length == 1) + return 1; + + int result = 1; + + int group_size = 1; + int groups_count = 1; + char prev_char = word[0]; + + for (size_t i = 1; i < word_length; ++i) { + char curr_char = word[i]; + + if (curr_char != prev_char) { + if (group_size > 1) { + result += group_size - 1; + } + + groups_count += 1; + group_size = 1; + } else { + group_size += 1; + } + + prev_char = curr_char; + } + + if (group_size > 1) { + result += group_size - 1; + } + + + return result; + } + }; +} + +#include + +TEST(P3330, 1) { + Solution s; + EXPECT_EQ(s.possibleStringCount("abbcccc"), 5); +} + +TEST(P3330, 2) { + Solution s; + EXPECT_EQ(s.possibleStringCount("abcd"), 1); +} + +TEST(P3330, 3) { + Solution s; + EXPECT_EQ(s.possibleStringCount("aaaa"), 4); +} \ No newline at end of file