#include <iostream> #include <vector> using namespace std; string strink; int x; long long wynik; int main() { cin >> strink; vector <bool> t; for (int i=0;i<strink.size();++i) if (strink[i]=='a' || strink[i]== 'e' ||strink[i]== 'i'||strink[i]== 'o'||strink[i]== 'u'||strink[i]== 'y') t.push_back(1); else t.push_back(0); int n = t.size(); vector <int> pom; for (int i=2;i<n;++i) if (t[i]==t[i-1]&&t[i]==t[i-2]) pom.push_back(i); if (pom.empty()) { cout << 0; return 0; } if (pom.size()==1) { x=(pom[0]-1)*(n-pom[0]); cout << x; return 0; } for (int i=0;i<pom.size()-1;++i) { wynik+= (pom[i]-1) * (pom[i+1]-pom[i]); //cout << wynik << endl; } // cout << wynik << endl; wynik+= (pom.back()-1) * (n-pom.back()); cout << wynik; return 0; } /* wynik += (pom[0]-1) * (pom[1]-pom[0]); cout << wynik << endl; for (int i=1;i<pom.size()-1;++i) { wynik+=(pom[i]+1-pom[i-1])*; } cout << wynik << endl; wynik += (n-pom.back())*(pom.back()+1-pom[pom.size()-2]); */
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> #include <vector> using namespace std; string strink; int x; long long wynik; int main() { cin >> strink; vector <bool> t; for (int i=0;i<strink.size();++i) if (strink[i]=='a' || strink[i]== 'e' ||strink[i]== 'i'||strink[i]== 'o'||strink[i]== 'u'||strink[i]== 'y') t.push_back(1); else t.push_back(0); int n = t.size(); vector <int> pom; for (int i=2;i<n;++i) if (t[i]==t[i-1]&&t[i]==t[i-2]) pom.push_back(i); if (pom.empty()) { cout << 0; return 0; } if (pom.size()==1) { x=(pom[0]-1)*(n-pom[0]); cout << x; return 0; } for (int i=0;i<pom.size()-1;++i) { wynik+= (pom[i]-1) * (pom[i+1]-pom[i]); //cout << wynik << endl; } // cout << wynik << endl; wynik+= (pom.back()-1) * (n-pom.back()); cout << wynik; return 0; } /* wynik += (pom[0]-1) * (pom[1]-pom[0]); cout << wynik << endl; for (int i=1;i<pom.size()-1;++i) { wynik+=(pom[i]+1-pom[i-1])*; } cout << wynik << endl; wynik += (n-pom.back())*(pom.back()+1-pom[pom.size()-2]); */ |