#include <bits/stdc++.h> using namespace std; inline bool is_vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } inline bool check_sequence(char a, char b, char c) { return (is_vowel(a) && is_vowel(b) && is_vowel(c)) || (!is_vowel(a) && !is_vowel(b) && !is_vowel(c)); } int main() { ios_base::sync_with_stdio(false); string T; cin >> T; long int n = (long int)T.size(); if(n < 3) { cout << "0" << endl; } else { long int res = 3; long int last = -1; for(long int i = 2; i < n; i++) { if(check_sequence(T[i - 2], T[i - 1], T[i])) { last = i - 2; } res += (i - last); } cout << (n * (n + 1) / 2) - res << 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 | #include <bits/stdc++.h> using namespace std; inline bool is_vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } inline bool check_sequence(char a, char b, char c) { return (is_vowel(a) && is_vowel(b) && is_vowel(c)) || (!is_vowel(a) && !is_vowel(b) && !is_vowel(c)); } int main() { ios_base::sync_with_stdio(false); string T; cin >> T; long int n = (long int)T.size(); if(n < 3) { cout << "0" << endl; } else { long int res = 3; long int last = -1; for(long int i = 2; i < n; i++) { if(check_sequence(T[i - 2], T[i - 1], T[i])) { last = i - 2; } res += (i - last); } cout << (n * (n + 1) / 2) - res << endl; } return 0; } |