#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool is_vowel(char c) {
static string vowels = "aeiouy";
return vowels.find(c) != string::npos;
}
ll solve(string const& s) {
int n = s.size();
ll res = 0;
int j = 1;
auto tri = [&s](int k) {
return (is_vowel(s[k]) + is_vowel(s[k-1]) + is_vowel(s[k-2])) % 3 == 0;
};
for (int i = 0; i < n - 2; i++) {
if (i + 1 == j) {
do {
j++;
} while (j < n && !tri(j));
}
res += n - j;
}
return res;
}
int main() {
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; bool is_vowel(char c) { static string vowels = "aeiouy"; return vowels.find(c) != string::npos; } ll solve(string const& s) { int n = s.size(); ll res = 0; int j = 1; auto tri = [&s](int k) { return (is_vowel(s[k]) + is_vowel(s[k-1]) + is_vowel(s[k-2])) % 3 == 0; }; for (int i = 0; i < n - 2; i++) { if (i + 1 == j) { do { j++; } while (j < n && !tri(j)); } res += n - j; } return res; } int main() { string s; cin >> s; cout << solve(s) << endl; return 0; } |
English