//Piotr Golda #include <iostream> #include <string> using uint64_t = unsigned long long int; inline uint64_t ConsecutiveSubsequenceAmount( uint64_t n ) { return n*(n + 1) / 2 + 1 - n*2; } bool isVowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; } return false; } uint64_t Compute(const std::string& s) { uint64_t notHard{ 0 }; size_t start{ 0 }; bool same{ false }; for (size_t i = 2; i < s.size(); ++i) { if (isVowel(s[i - 2]) == isVowel(s[i - 1]) && isVowel(s[i - 1]) == isVowel(s[i]) ) { if (!same) { notHard += ConsecutiveSubsequenceAmount(i - start); } same = true; } else if (same) { same = false; start = i - 2; } } if (same) { notHard += ConsecutiveSubsequenceAmount(2); } else { notHard += ConsecutiveSubsequenceAmount(s.size() - start); } return ConsecutiveSubsequenceAmount(s.size()) - notHard; } int main() { std::ios_base::sync_with_stdio(false); std::string s{}; std::cin >> s; std::cout << Compute(s) << 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 58 59 60 61 62 63 64 65 66 | //Piotr Golda #include <iostream> #include <string> using uint64_t = unsigned long long int; inline uint64_t ConsecutiveSubsequenceAmount( uint64_t n ) { return n*(n + 1) / 2 + 1 - n*2; } bool isVowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; } return false; } uint64_t Compute(const std::string& s) { uint64_t notHard{ 0 }; size_t start{ 0 }; bool same{ false }; for (size_t i = 2; i < s.size(); ++i) { if (isVowel(s[i - 2]) == isVowel(s[i - 1]) && isVowel(s[i - 1]) == isVowel(s[i]) ) { if (!same) { notHard += ConsecutiveSubsequenceAmount(i - start); } same = true; } else if (same) { same = false; start = i - 2; } } if (same) { notHard += ConsecutiveSubsequenceAmount(2); } else { notHard += ConsecutiveSubsequenceAmount(s.size() - start); } return ConsecutiveSubsequenceAmount(s.size()) - notHard; } int main() { std::ios_base::sync_with_stdio(false); std::string s{}; std::cin >> s; std::cout << Compute(s) << std::endl; return 0; } |