#include <bits/stdc++.h> using namespace std; using ll = long long; bool vowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } ll solve(string s) { int n = s.size(); vector<int> vow(n); for (int i = 0; i < n; i++) { vow[i] = vowel(s[i]); } ll res = 0; int j = 0; for (int i = 0; i < n; i++) { while (j < n && (j < i + 2 || vow[j] != vow[j - 1] || vow[j - 1] != vow[j - 2])) { j++; } res += n - j; } return res; } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; cout << solve(s) << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; bool vowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } ll solve(string s) { int n = s.size(); vector<int> vow(n); for (int i = 0; i < n; i++) { vow[i] = vowel(s[i]); } ll res = 0; int j = 0; for (int i = 0; i < n; i++) { while (j < n && (j < i + 2 || vow[j] != vow[j - 1] || vow[j - 1] != vow[j - 2])) { j++; } res += n - j; } return res; } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; cout << solve(s) << "\n"; } |