#include <iostream> #include <map> #include <vector> using namespace std; long long w; string s; map<char,bool> vowel; vector<long long>v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); vowel['a']=1; vowel['e']=1; vowel['o']=1; vowel['u']=1; vowel['y']=1; vowel['i']=1; cin>>s; long long sl=s.size(); w=sl*(sl+1)/2; v.push_back(1); for(long long i=1;i<=sl-1;i++){ if(!v.back()) v.resize(v.size()-1); if(v.back()<0){ if(vowel[s[i-1]]==vowel[s[i]]) v.back()--; else v.push_back(1); }else{ if(i<sl-1){ long long c=vowel[s[i-1]]+vowel[s[i]]+vowel[s[i+1]]; if(c==3 || !c){ v.back()--; if(!v.back()) v.resize(v.size()-1); v.push_back(-3); i++; } else v.back()++; } else v.back()++; } } for(long long i=0;i<v.size();i++){ //cout<<v[i]<<endl; long long d; if(v[i]>0){ d=v[i]*(v[i]+1)/2; if(i) d+=2*v[i]; if(i!=v.size()-1) d+=2*v[i]; if(i && i!=v.size()-1) d+=4; } else{ d=-1*(2*v[i]+1); if(i && v[i-1]<0) d+=4; } //cout<<d<<"-"<<endl; w-=d; } cout<<w; 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <iostream> #include <map> #include <vector> using namespace std; long long w; string s; map<char,bool> vowel; vector<long long>v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); vowel['a']=1; vowel['e']=1; vowel['o']=1; vowel['u']=1; vowel['y']=1; vowel['i']=1; cin>>s; long long sl=s.size(); w=sl*(sl+1)/2; v.push_back(1); for(long long i=1;i<=sl-1;i++){ if(!v.back()) v.resize(v.size()-1); if(v.back()<0){ if(vowel[s[i-1]]==vowel[s[i]]) v.back()--; else v.push_back(1); }else{ if(i<sl-1){ long long c=vowel[s[i-1]]+vowel[s[i]]+vowel[s[i+1]]; if(c==3 || !c){ v.back()--; if(!v.back()) v.resize(v.size()-1); v.push_back(-3); i++; } else v.back()++; } else v.back()++; } } for(long long i=0;i<v.size();i++){ //cout<<v[i]<<endl; long long d; if(v[i]>0){ d=v[i]*(v[i]+1)/2; if(i) d+=2*v[i]; if(i!=v.size()-1) d+=2*v[i]; if(i && i!=v.size()-1) d+=4; } else{ d=-1*(2*v[i]+1); if(i && v[i-1]<0) d+=4; } //cout<<d<<"-"<<endl; w-=d; } cout<<w; return 0; } |