#include<bits/stdc++.h> #define SZ(a) (int)a.size() #define ll long long using namespace std; inline bool sam(char c){ switch(c){ case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return 1; break; default: return 0; break; } } inline ll nC2(int n){//n choose 2 return ((ll)n*(ll)(n-1))/2LL; } int main(){ ios_base::sync_with_stdio(0); string a; cin>>a; vector<bool> k(SZ(a),0); for(int i=0;i<SZ(a);i++){ k[i]=sam(a[i]); } int p=-1; ll sm=1; for(int i=2;i<SZ(k);i++){ if(k[i]==k[i-1]&&k[i]==k[i-2]){ sm+=nC2(i-p)-1; p=i-2; } } sm+=nC2(SZ(k)-p)-1; ll f=nC2(SZ(k)+1)-sm; cout<<f; }
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 | #include<bits/stdc++.h> #define SZ(a) (int)a.size() #define ll long long using namespace std; inline bool sam(char c){ switch(c){ case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return 1; break; default: return 0; break; } } inline ll nC2(int n){//n choose 2 return ((ll)n*(ll)(n-1))/2LL; } int main(){ ios_base::sync_with_stdio(0); string a; cin>>a; vector<bool> k(SZ(a),0); for(int i=0;i<SZ(a);i++){ k[i]=sam(a[i]); } int p=-1; ll sm=1; for(int i=2;i<SZ(k);i++){ if(k[i]==k[i-1]&&k[i]==k[i-2]){ sm+=nC2(i-p)-1; p=i-2; } } sm+=nC2(SZ(k)-p)-1; ll f=nC2(SZ(k)+1)-sm; cout<<f; } |