#include <bits/stdc++.h> using namespace std; vector <bool> tab; int L = 0, R = 2; string slowo; long long wynik; bool war; char a; int main() { cin >> slowo; int n = slowo.size(); for (int i = 0; i < n; i++) { a = slowo[i]; if (a == 'a'|| a == 'e' || a == 'o' || a == 'y' || a == 'u' || a == 'i') tab.push_back(0); else tab.push_back(1); } if (n == 1 || n == 2) { cout << "0"; return 0; } if (tab[0]==tab[1] && tab[1]==tab[2]) war = 1; while (L < n) { if (war == 0 && R + 1 < n) { if (tab[R-1] == tab[R] && tab[R] == tab[R+1]) war = 1; R++; } else if (war == 1) { wynik += n - R; if (tab[L] == tab[L+1] && tab[L+1] == tab[L+2]) war = 0; L++; } else { cout << wynik; 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 <bits/stdc++.h> using namespace std; vector <bool> tab; int L = 0, R = 2; string slowo; long long wynik; bool war; char a; int main() { cin >> slowo; int n = slowo.size(); for (int i = 0; i < n; i++) { a = slowo[i]; if (a == 'a'|| a == 'e' || a == 'o' || a == 'y' || a == 'u' || a == 'i') tab.push_back(0); else tab.push_back(1); } if (n == 1 || n == 2) { cout << "0"; return 0; } if (tab[0]==tab[1] && tab[1]==tab[2]) war = 1; while (L < n) { if (war == 0 && R + 1 < n) { if (tab[R-1] == tab[R] && tab[R] == tab[R+1]) war = 1; R++; } else if (war == 1) { wynik += n - R; if (tab[L] == tab[L+1] && tab[L+1] == tab[L+2]) war = 0; L++; } else { cout << wynik; return 0; } } } |