#include <bits/stdc++.h> using namespace std; #define MAXN 200069 set <char> Vow; int n,pre,v; short tab[MAXN]; long long res; bool pass; char c; string inp; void Init() { Vow.insert('a'); Vow.insert('e'); Vow.insert('o'); Vow.insert('u'); Vow.insert('y'); Vow.insert('i'); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Init(); cin >> inp; n = inp.size(); for (int i=0; i!=n; ++i) { c = inp[i]; tab[i+1] = (Vow.find(c) != Vow.end()); //cout << tab[i+1]; } res = 0; res >>= 1; pre = 0; for (int i=2; i<n; ++i) { if (tab[i]== tab[i-1] && tab[i] == tab[i+1]) { res += (long long)(i-1-pre)*(long long)(n-i); pre = i-1; } } cout << res; 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 <bits/stdc++.h> using namespace std; #define MAXN 200069 set <char> Vow; int n,pre,v; short tab[MAXN]; long long res; bool pass; char c; string inp; void Init() { Vow.insert('a'); Vow.insert('e'); Vow.insert('o'); Vow.insert('u'); Vow.insert('y'); Vow.insert('i'); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Init(); cin >> inp; n = inp.size(); for (int i=0; i!=n; ++i) { c = inp[i]; tab[i+1] = (Vow.find(c) != Vow.end()); //cout << tab[i+1]; } res = 0; res >>= 1; pre = 0; for (int i=2; i<n; ++i) { if (tab[i]== tab[i-1] && tab[i] == tab[i+1]) { res += (long long)(i-1-pre)*(long long)(n-i); pre = i-1; } } cout << res; return 0; } |