#include <iostream> int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::string word; std::cin >> word; unsigned n = word.size(); size_t result = 0; for (unsigned start = 0; start < n; start++) { unsigned as = word[start] == 'a', bs = word[start] == 'b', cs = word[start] == 'c'; result++; for (unsigned end = start + 1; end < n; end++) { switch (word[end]) { case 'a': as++; break; case 'b': bs++; break; case 'c': cs++; break; default: __builtin_unreachable(); } if ((as == bs || !as || !bs) && (as == cs || !as || !cs) && (bs == cs || !bs || !cs)) { result++; } } } std::cout << result << std::endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream> int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::string word; std::cin >> word; unsigned n = word.size(); size_t result = 0; for (unsigned start = 0; start < n; start++) { unsigned as = word[start] == 'a', bs = word[start] == 'b', cs = word[start] == 'c'; result++; for (unsigned end = start + 1; end < n; end++) { switch (word[end]) { case 'a': as++; break; case 'b': bs++; break; case 'c': cs++; break; default: __builtin_unreachable(); } if ((as == bs || !as || !bs) && (as == cs || !as || !cs) && (bs == cs || !bs || !cs)) { result++; } } } std::cout << result << std::endl; } |