//#include "/Users/dimazhylko/CPPProjects/bits/stdc++.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; char sp[] = {'a', 'e', 'i', 'o', 'u', 'y'}; stack<int> st; bool find(char s){ for(int i = 0;i<6;i++){ if(s==sp[i])return true; } return false; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; for(int i = 0;i<s.length()-2;i++){ if( (find(s[i]) && find(s[i+1]) && find(s[i+2])) || (!find(s[i]) && !find(s[i+1]) && !find(s[i+2])) ){ st.push(i+2); } } ll res = st.size(); for(ll i = s.length()-1ll;i>=2ll && !st.empty();i--){ if(i<st.top())st.pop(); if(st.empty())break; if(st.top()==i){ res+=i-2ll; continue; } res+= i-(i-st.top()-1) - 2; } cout<<res<<endl; 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 | //#include "/Users/dimazhylko/CPPProjects/bits/stdc++.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; char sp[] = {'a', 'e', 'i', 'o', 'u', 'y'}; stack<int> st; bool find(char s){ for(int i = 0;i<6;i++){ if(s==sp[i])return true; } return false; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; for(int i = 0;i<s.length()-2;i++){ if( (find(s[i]) && find(s[i+1]) && find(s[i+2])) || (!find(s[i]) && !find(s[i+1]) && !find(s[i+2])) ){ st.push(i+2); } } ll res = st.size(); for(ll i = s.length()-1ll;i>=2ll && !st.empty();i--){ if(i<st.top())st.pop(); if(st.empty())break; if(st.top()==i){ res+=i-2ll; continue; } res+= i-(i-st.top()-1) - 2; } cout<<res<<endl; return 0; } |