#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; int main() { ios::sync_with_stdio(false); cin.tie(0); unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; string str; cin >> str; bool was_vowel = false; int cnt = 0, prev = -1; long long res = 0; for (int i = 0; i < str.size(); ++i) { if ( (vowels.find(str[i]) != vowels.end()) == was_vowel) ++cnt; else { cnt = 1; was_vowel = !was_vowel; } if (cnt >= 3) prev = i; if (prev >= 0) res += prev - 1; } cout << res << '\n'; 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 | #include <algorithm> #include <cmath> #include <iostream> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; int main() { ios::sync_with_stdio(false); cin.tie(0); unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; string str; cin >> str; bool was_vowel = false; int cnt = 0, prev = -1; long long res = 0; for (int i = 0; i < str.size(); ++i) { if ( (vowels.find(str[i]) != vowels.end()) == was_vowel) ++cnt; else { cnt = 1; was_vowel = !was_vowel; } if (cnt >= 3) prev = i; if (prev >= 0) res += prev - 1; } cout << res << '\n'; return 0; } |