#include <iostream> #include <string> using namespace std; bool is_vowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } string a; int main() { cin >> a; bool vowel = is_vowel(a[0]); long long result = 0; int counter = 1; int j = 1; for (size_t i = 1; i < a.length(); ++i) { bool is_next_vowel = is_vowel(a[i]); if ((vowel and is_next_vowel) or ((not vowel) and (not is_next_vowel))) { if (++counter > 2) { result += (i - j) * (a.length() - i); j = i; } } else { vowel = is_next_vowel; counter = 1; } } cout << result; 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 | #include <iostream> #include <string> using namespace std; bool is_vowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } string a; int main() { cin >> a; bool vowel = is_vowel(a[0]); long long result = 0; int counter = 1; int j = 1; for (size_t i = 1; i < a.length(); ++i) { bool is_next_vowel = is_vowel(a[i]); if ((vowel and is_next_vowel) or ((not vowel) and (not is_next_vowel))) { if (++counter > 2) { result += (i - j) * (a.length() - i); j = i; } } else { vowel = is_next_vowel; counter = 1; } } cout << result; return 0; } |