#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); }