#include <iostream> using namespace::std; const int N = (int) 2e5 + 5; string s; bool tab[N]; int ost[N], n; long long wyn; bool samo(char c) { return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c =='u' or c == 'y'; } void ustaw(int v) { ost[v] = ost[v + 1]; if (v > n - 3) return; if ((!tab[v] and !tab[v + 1] and !tab[v + 2]) or (tab[v] and tab[v + 1] and tab[v + 2])) ost[v] = v + 2; } int main() { ios_base::sync_with_stdio(false); cin >> s; n = (int) s.size(); for (int i = 0; i < n; i++) tab[i] = samo(s[i]); ost[n] = n; wyn += ((long long)n * (n + 1)) / 2; for (int i = n - 1; i >= 0; i--) { ustaw(i); wyn -= ost[i] - i; } cout << wyn; }
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 | #include <iostream> using namespace::std; const int N = (int) 2e5 + 5; string s; bool tab[N]; int ost[N], n; long long wyn; bool samo(char c) { return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c =='u' or c == 'y'; } void ustaw(int v) { ost[v] = ost[v + 1]; if (v > n - 3) return; if ((!tab[v] and !tab[v + 1] and !tab[v + 2]) or (tab[v] and tab[v + 1] and tab[v + 2])) ost[v] = v + 2; } int main() { ios_base::sync_with_stdio(false); cin >> s; n = (int) s.size(); for (int i = 0; i < n; i++) tab[i] = samo(s[i]); ost[n] = n; wyn += ((long long)n * (n + 1)) / 2; for (int i = n - 1; i >= 0; i--) { ustaw(i); wyn -= ost[i] - i; } cout << wyn; } |