#include <stdio.h> #include <iostream> #include <set> #include <string> #include <stdint.h> namespace { bool is_vowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return true; } return false; } bool is_consonant(char c) { return !is_vowel(c); } bool is_triple(const std::string &s, int index) { if (is_vowel(s.at(index)) && is_vowel(s.at(index + 1)) && is_vowel(s.at(index + 2))) { return true; } if (is_consonant(s.at(index)) && is_consonant(s.at(index + 1)) && is_consonant(s.at(index + 2))) { return true; } return false; } } // namespace anonymous int main() { std::string text; std::getline(std::cin, text); int length = text.length(); int64_t count = 0; int last_triple = -1; for (int i = 0; i < length - 2; ++i) { if (!is_triple(text, i)) { continue; } int64_t before = i - last_triple - 1; int64_t after = length - i - 3; count += (before + 1) * (after + 1); last_triple = i; } std::cout << count << std::endl; return 0; }
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <stdio.h> #include <iostream> #include <set> #include <string> #include <stdint.h> namespace { bool is_vowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return true; } return false; } bool is_consonant(char c) { return !is_vowel(c); } bool is_triple(const std::string &s, int index) { if (is_vowel(s.at(index)) && is_vowel(s.at(index + 1)) && is_vowel(s.at(index + 2))) { return true; } if (is_consonant(s.at(index)) && is_consonant(s.at(index + 1)) && is_consonant(s.at(index + 2))) { return true; } return false; } } // namespace anonymous int main() { std::string text; std::getline(std::cin, text); int length = text.length(); int64_t count = 0; int last_triple = -1; for (int i = 0; i < length - 2; ++i) { if (!is_triple(text, i)) { continue; } int64_t before = i - last_triple - 1; int64_t after = length - i - 3; count += (before + 1) * (after + 1); last_triple = i; } std::cout << count << std::endl; return 0; } |