#include <bits/stdc++.h> using namespace std; bool s[200013],trud[200013]; int last[200013]; string t; int n; long long res=0; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin >> t; n=t.size(); for(int i=0; i<n; i++){ if(t[i]=='a' || t[i]=='o' || t[i]=='e' || t[i]=='i' || t[i]=='u' || t[i]=='y') s[i]=true; else s[i]=false; } for(int i=0; i<n-2; i++){ if(s[i]==s[i+1] && s[i+1]==s[i+2]) trud[i]=true; else trud[i]=false; } last[0]=-1; for(int i=1; i<n; i++){ if(trud[i-1]) last[i]=i-1; else last[i]=last[i-1]; } for(int i=0; i<n; i++){ if(trud[i]){ res=res+(long long)((long long)(i-last[i])*(long long)(n-i-2)); } } cout << res; 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 | #include <bits/stdc++.h> using namespace std; bool s[200013],trud[200013]; int last[200013]; string t; int n; long long res=0; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin >> t; n=t.size(); for(int i=0; i<n; i++){ if(t[i]=='a' || t[i]=='o' || t[i]=='e' || t[i]=='i' || t[i]=='u' || t[i]=='y') s[i]=true; else s[i]=false; } for(int i=0; i<n-2; i++){ if(s[i]==s[i+1] && s[i+1]==s[i+2]) trud[i]=true; else trud[i]=false; } last[0]=-1; for(int i=1; i<n; i++){ if(trud[i-1]) last[i]=i-1; else last[i]=last[i-1]; } for(int i=0; i<n; i++){ if(trud[i]){ res=res+(long long)((long long)(i-last[i])*(long long)(n-i-2)); } } cout << res; return 0; } |