#include<bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 2000000; string n; bool a[N+10]; ll ans,r; vector<ll>v; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; r=n.size(); for(int i=0; i<r; ++i){ if(n[i]=='a' || n[i]=='e' || n[i]=='i' || n[i]=='o' || n[i]=='u' || n[i]=='y'){ a[i]=1; } } for(int i=r-3; i>=0; --i){ if(a[i]==a[i+1] && a[i]==a[i+2]){ v.push_back(i); } } for(int i=0; i<r; ++i){ if(v.empty())break; ans+=r-v.back()-2; while(v.back()<=i)v.pop_back(); } cout<<ans; }
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 | #include<bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 2000000; string n; bool a[N+10]; ll ans,r; vector<ll>v; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; r=n.size(); for(int i=0; i<r; ++i){ if(n[i]=='a' || n[i]=='e' || n[i]=='i' || n[i]=='o' || n[i]=='u' || n[i]=='y'){ a[i]=1; } } for(int i=r-3; i>=0; --i){ if(a[i]==a[i+1] && a[i]==a[i+2]){ v.push_back(i); } } for(int i=0; i<r; ++i){ if(v.empty())break; ans+=r-v.back()-2; while(v.back()<=i)v.pop_back(); } cout<<ans; } |