#include <string> #include <iostream> #include <vector> using namespace std; namespace { bool is_vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } long long substrings3plus(int n) { if (n < 3) return 0; return static_cast<long long>(n - 1) * (n - 2) / 2; } long long solve(string const& s) { int n = s.size(); vector<bool> vowel(n); for (int i = 0; i < n; ++i) { vowel[i] = is_vowel(s[i]); } long long res = substrings3plus(n); int i = 0; int current = -2; while (i < n) { int j = i; while (j < n && vowel[i] == vowel[j]) ++j; int len = j - i; i = j; if (len >= 3) { res -= substrings3plus(current + 4); current = 0; } else { current += len; } } res -= substrings3plus(current + 2); return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; cout << solve(s) << 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 | #include <string> #include <iostream> #include <vector> using namespace std; namespace { bool is_vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } long long substrings3plus(int n) { if (n < 3) return 0; return static_cast<long long>(n - 1) * (n - 2) / 2; } long long solve(string const& s) { int n = s.size(); vector<bool> vowel(n); for (int i = 0; i < n; ++i) { vowel[i] = is_vowel(s[i]); } long long res = substrings3plus(n); int i = 0; int current = -2; while (i < n) { int j = i; while (j < n && vowel[i] == vowel[j]) ++j; int len = j - i; i = j; if (len >= 3) { res -= substrings3plus(current + 4); current = 0; } else { current += len; } } res -= substrings3plus(current + 2); return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; cout << solve(s) << endl; return 0; } |