#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N=200005; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int t[N]; string s; cin>>s; long long n=s.size(); for(int i=0; i<s.size(); i++){ if(s[i]=='a' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='y' || s[i]=='e') t[i]=0; else t[i]=1; } long long sum=3; if(n==1 || n==2){ cout<<0<<endl; return 0; } int b=0; for(int i=2; i<n; i++){ if(t[i]==t[i-1] && t[i-1]==t[i-2]){ b=i-1; sum+=2; } else sum+=i-b+1; //cout<<sum<<endl; } //cout<<sum<<endl; long long mx=n*(n+1)/2; cout<<mx-sum<<endl; }
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; const int N=200005; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int t[N]; string s; cin>>s; long long n=s.size(); for(int i=0; i<s.size(); i++){ if(s[i]=='a' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='y' || s[i]=='e') t[i]=0; else t[i]=1; } long long sum=3; if(n==1 || n==2){ cout<<0<<endl; return 0; } int b=0; for(int i=2; i<n; i++){ if(t[i]==t[i-1] && t[i-1]==t[i-2]){ b=i-1; sum+=2; } else sum+=i-b+1; //cout<<sum<<endl; } //cout<<sum<<endl; long long mx=n*(n+1)/2; cout<<mx-sum<<endl; } |