#include <iostream> #include <vector> #include <string> using namespace std; bool spolgloska(char z){ if(z=='a' || z=='e' || z=='i' || z=='o' || z=='u' || z=='y') return 0; return 1; } int count(string wyraz){ if(wyraz.size()<3) return 0; int count = 0; vector<int> triple; for(int i = 0; i<wyraz.size()-2; i++){ if((spolgloska(wyraz[i]) && spolgloska(wyraz[i+1]) && spolgloska(wyraz[i+2]))|| (!spolgloska(wyraz[i]) && !spolgloska(wyraz[i+1]) && !spolgloska(wyraz[i+2]))){ triple.push_back(i); } } if(triple.size()==0) return 0; count += triple.size(); for(int i=0;i<triple.size();i++) count+=triple[i]; for(int i=0;i<triple.size()-1;i++){ int j = triple[i+1] - triple[i] - 1; count += j*(triple[i]+1); } int j = wyraz.size()-triple[triple.size()-1]-3; count += j*(triple[triple.size()-1]+1); return count; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string wyraz; cin >> wyraz; cout<<count(wyraz); 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 | #include <iostream> #include <vector> #include <string> using namespace std; bool spolgloska(char z){ if(z=='a' || z=='e' || z=='i' || z=='o' || z=='u' || z=='y') return 0; return 1; } int count(string wyraz){ if(wyraz.size()<3) return 0; int count = 0; vector<int> triple; for(int i = 0; i<wyraz.size()-2; i++){ if((spolgloska(wyraz[i]) && spolgloska(wyraz[i+1]) && spolgloska(wyraz[i+2]))|| (!spolgloska(wyraz[i]) && !spolgloska(wyraz[i+1]) && !spolgloska(wyraz[i+2]))){ triple.push_back(i); } } if(triple.size()==0) return 0; count += triple.size(); for(int i=0;i<triple.size();i++) count+=triple[i]; for(int i=0;i<triple.size()-1;i++){ int j = triple[i+1] - triple[i] - 1; count += j*(triple[i]+1); } int j = wyraz.size()-triple[triple.size()-1]-3; count += j*(triple[triple.size()-1]+1); return count; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string wyraz; cin >> wyraz; cout<<count(wyraz); return 0; } |