#include <iostream> #include <string> #include <set> using namespace std; string s; set <char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; long long ans; int main() { ios_base::sync_with_stdio(0); cin >> s; s += '#'; for (long long i = 1, vowel = vowels.count(s[0]) ? 1 : 0, newVowel = 0, xCount = 1, lastX = 2e5; i < s.size(); i++) { newVowel = vowels.count(s[i]) ? 1 : 0; if (vowel == newVowel && s[i] != '#') { xCount++; } else { if (xCount >= 3) { long long aCount = i - xCount - (lastX == 2e5 ? 0 : lastX), bCount = s.size() - i - 1; ans += (long long) (xCount - 3 + 1) * aCount; ans += (long long) (xCount - 3 + 1) * bCount; ans += (long long) aCount * bCount; ans += (long long) (xCount - 3 + 1) * (xCount - 3 + 2) / 2; lastX = i - 2; } xCount = 1; } vowel = newVowel; } cout << ans; }
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 | #include <iostream> #include <string> #include <set> using namespace std; string s; set <char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; long long ans; int main() { ios_base::sync_with_stdio(0); cin >> s; s += '#'; for (long long i = 1, vowel = vowels.count(s[0]) ? 1 : 0, newVowel = 0, xCount = 1, lastX = 2e5; i < s.size(); i++) { newVowel = vowels.count(s[i]) ? 1 : 0; if (vowel == newVowel && s[i] != '#') { xCount++; } else { if (xCount >= 3) { long long aCount = i - xCount - (lastX == 2e5 ? 0 : lastX), bCount = s.size() - i - 1; ans += (long long) (xCount - 3 + 1) * aCount; ans += (long long) (xCount - 3 + 1) * bCount; ans += (long long) aCount * bCount; ans += (long long) (xCount - 3 + 1) * (xCount - 3 + 2) / 2; lastX = i - 2; } xCount = 1; } vowel = newVowel; } cout << ans; } |