#include <iostream> std::string word; bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main() { std::cin >> word; unsigned long long result = 0; int last = -1; for(int i = 0; i < word.length() - 2; ++i) { if(isVowel(word[i]) == isVowel(word[i + 1]) && isVowel(word[i + 1]) == isVowel(word[i + 2])) { result += (long long)(i - last) * (long long)(word.length() - i - 2); last = i; } } std::cout << result << 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 | #include <iostream> std::string word; bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main() { std::cin >> word; unsigned long long result = 0; int last = -1; for(int i = 0; i < word.length() - 2; ++i) { if(isVowel(word[i]) == isVowel(word[i + 1]) && isVowel(word[i + 1]) == isVowel(word[i + 2])) { result += (long long)(i - last) * (long long)(word.length() - i - 2); last = i; } } std::cout << result << std::endl; return 0; } |