#include <bits/stdc++.h>
#define ll long long
const int MAX_N = 2e5;
int t[MAX_N+3];
std::string s;
ll n;
void input(){
std::cin >> s;
n = s.length();
for (int i = 0; i < n; i++){
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y')
t[i] = 1;
else
t[i] = 0;
}
}
int main(){
std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
// a, e, i, o, u, y
input();
ll res = 0;
ll head = 0;
for (ll tail = 0; tail < n; tail++){
while (head < n-1 && (head - tail + 1 <= 1 || (t[head] + t[head-1] + t[head+1] != 0 && t[head] + t[head-1] + t[head+1] != 3)))
head++;
res += head - tail + 1;
}
std::cout << n*(n+1)/2 - res << "\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 | #include <bits/stdc++.h> #define ll long long const int MAX_N = 2e5; int t[MAX_N+3]; std::string s; ll n; void input(){ std::cin >> s; n = s.length(); for (int i = 0; i < n; i++){ if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') t[i] = 1; else t[i] = 0; } } int main(){ std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); // a, e, i, o, u, y input(); ll res = 0; ll head = 0; for (ll tail = 0; tail < n; tail++){ while (head < n-1 && (head - tail + 1 <= 1 || (t[head] + t[head-1] + t[head+1] != 0 && t[head] + t[head-1] + t[head+1] != 3))) head++; res += head - tail + 1; } std::cout << n*(n+1)/2 - res << "\n"; } |
English