#include <bits/stdc++.h> using namespace std; template <typename T> T load() { T r; cin >> r; return r; } template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; } bool isVowel(char c) { static array<bool, 256> lookup = [](){ auto lookup = array<bool, 256>{}; for (auto c='a'; c<='z'; ++c) lookup[c] = false; lookup['a'] = lookup['e'] = lookup['i'] = lookup['o'] = lookup['u'] = lookup['y'] = true; return lookup; }(); return lookup[c]; } template <typename T> bool same3(const T& a, const T& b, const T& c) { return a == b and b == c; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto text = load<string>(); auto n = (int)text.size(); auto j = 0; auto able = 0ll; for (auto i=0; i<n; ++i) { while (j < n and (j < i+2 or not same3(isVowel(text[j-2]), isVowel(text[j-1]), isVowel(text[j])))) ++j; able += j - i; } auto answer = (long long)n * (n+1) / 2 - able; cout << answer << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; template <typename T> T load() { T r; cin >> r; return r; } template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; } bool isVowel(char c) { static array<bool, 256> lookup = [](){ auto lookup = array<bool, 256>{}; for (auto c='a'; c<='z'; ++c) lookup[c] = false; lookup['a'] = lookup['e'] = lookup['i'] = lookup['o'] = lookup['u'] = lookup['y'] = true; return lookup; }(); return lookup[c]; } template <typename T> bool same3(const T& a, const T& b, const T& c) { return a == b and b == c; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto text = load<string>(); auto n = (int)text.size(); auto j = 0; auto able = 0ll; for (auto i=0; i<n; ++i) { while (j < n and (j < i+2 or not same3(isVowel(text[j-2]), isVowel(text[j-1]), isVowel(text[j])))) ++j; able += j - i; } auto answer = (long long)n * (n+1) / 2 - able; cout << answer << '\n'; } |