#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <set> #include <map> #include <bits/stdc++.h> using namespace std; #define int long long bool bad[200005]; int32_t main() { ios::sync_with_stdio(0); string s; cin >> s; int result = s.size()*(s.size()-1)/2 + s.size(); set<char> S {'a', 'e', 'i', 'o', 'u', 'y'}; for(int i=0; i<s.size(); i++) { if(S.count(s[i])) s[i] = 0; else s[i] = 1; } int beg = 0; for(int i=2; i<s.size(); i++) { if(s[i] == s[i-1] && s[i] == s[i-2]) bad[i] = 1; } int ix = 0; while(ix < s.size() && bad[ix] == 0) ++ix; for(int i=0; i<s.size(); i++) { ix = max(ix, i + 2); ix = min(ix, (int)s.size()); while(ix < s.size() && bad[ix] == 0) ++ix; result -= (ix - i); } cout << result << endl; }
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 56 57 | #include <iostream> #include <vector> #include <queue> #include <algorithm> #include <set> #include <map> #include <bits/stdc++.h> using namespace std; #define int long long bool bad[200005]; int32_t main() { ios::sync_with_stdio(0); string s; cin >> s; int result = s.size()*(s.size()-1)/2 + s.size(); set<char> S {'a', 'e', 'i', 'o', 'u', 'y'}; for(int i=0; i<s.size(); i++) { if(S.count(s[i])) s[i] = 0; else s[i] = 1; } int beg = 0; for(int i=2; i<s.size(); i++) { if(s[i] == s[i-1] && s[i] == s[i-2]) bad[i] = 1; } int ix = 0; while(ix < s.size() && bad[ix] == 0) ++ix; for(int i=0; i<s.size(); i++) { ix = max(ix, i + 2); ix = min(ix, (int)s.size()); while(ix < s.size() && bad[ix] == 0) ++ix; result -= (ix - i); } cout << result << endl; } |