#include <iostream> using namespace std; inline bool vowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } inline unsigned long long nn2(unsigned long long n) { return n*(n+1)/2; } int main() { ios_base::sync_with_stdio(false); string s; s.reserve(200000); cin >> s; unsigned l = s.length(); unsigned long long sum = nn2(l); int cnt = 0; int cntSince = 0; bool wasV = false; for (unsigned i = 0; i < l; i++) { if (wasV == vowel(s[i])) { cnt++; if (cnt >= 3) { cntSince = 1; } } else { cnt = 1; wasV = !wasV; } cntSince++; sum -= cntSince; } cout << sum << endl; 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 52 53 54 55 | #include <iostream> using namespace std; inline bool vowel(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } inline unsigned long long nn2(unsigned long long n) { return n*(n+1)/2; } int main() { ios_base::sync_with_stdio(false); string s; s.reserve(200000); cin >> s; unsigned l = s.length(); unsigned long long sum = nn2(l); int cnt = 0; int cntSince = 0; bool wasV = false; for (unsigned i = 0; i < l; i++) { if (wasV == vowel(s[i])) { cnt++; if (cnt >= 3) { cntSince = 1; } } else { cnt = 1; wasV = !wasV; } cntSince++; sum -= cntSince; } cout << sum << endl; return 0; } |