#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+5; bool xd[200]; char s[N]; int seq[N]; int n; int main() { for(int c : {'a', 'e', 'i', 'o', 'u', 'y'}) xd[c] = 1; scanf("%s",s+1); n = strlen(s+1); for(int i = 1; i <= n; ++i) { if(xd[(int)s[i]]) seq[i] = 1; } int wsk = 1; ll res = 0; for(int i = 1; i <= n-2; ++i) { wsk = max(wsk, i+2); while(wsk <= n && !(seq[wsk] == seq[wsk-1] && seq[wsk-1] == seq[wsk-2])) wsk++; res += n-wsk+1; } printf("%lld\n", res); }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+5; bool xd[200]; char s[N]; int seq[N]; int n; int main() { for(int c : {'a', 'e', 'i', 'o', 'u', 'y'}) xd[c] = 1; scanf("%s",s+1); n = strlen(s+1); for(int i = 1; i <= n; ++i) { if(xd[(int)s[i]]) seq[i] = 1; } int wsk = 1; ll res = 0; for(int i = 1; i <= n-2; ++i) { wsk = max(wsk, i+2); while(wsk <= n && !(seq[wsk] == seq[wsk-1] && seq[wsk-1] == seq[wsk-2])) wsk++; res += n-wsk+1; } printf("%lld\n", res); } |