#include <iostream> using namespace std; void Rewrite(int n, string word, int *bin) { for(int i=0; i<n; ++i){ if(word[i]=='a' || word[i]=='o' || word[i]=='u' || word[i]=='e' || word[i]=='i' || word[i]=='y') bin[i]=0; else bin[i]=1; } } int main() { string word; cin >> word; bool one; int n=word.size(), bin[n]; long long int wynik=0, pom=1, id=-1; Rewrite(n, word, bin); if(bin[0]==0) one=false; else one=true; for(int i=1; i<n; ++i){ if(bin[i]==one){ pom+=1; if(pom>=3){ if(id==-1){ wynik+=(i-1)*(n-i); id=i-1; } else{ wynik+=(i-id-1)*(n-i); id=i-1; } } } else{ one=bin[i]; pom=1; } //cout<<i<<" "<<wynik<<endl; } cout<<wynik<<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 45 46 47 48 49 | #include <iostream> using namespace std; void Rewrite(int n, string word, int *bin) { for(int i=0; i<n; ++i){ if(word[i]=='a' || word[i]=='o' || word[i]=='u' || word[i]=='e' || word[i]=='i' || word[i]=='y') bin[i]=0; else bin[i]=1; } } int main() { string word; cin >> word; bool one; int n=word.size(), bin[n]; long long int wynik=0, pom=1, id=-1; Rewrite(n, word, bin); if(bin[0]==0) one=false; else one=true; for(int i=1; i<n; ++i){ if(bin[i]==one){ pom+=1; if(pom>=3){ if(id==-1){ wynik+=(i-1)*(n-i); id=i-1; } else{ wynik+=(i-id-1)*(n-i); id=i-1; } } } else{ one=bin[i]; pom=1; } //cout<<i<<" "<<wynik<<endl; } cout<<wynik<<endl; return 0; } |