#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline bool is_vowel(char c){
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}
int check_sequence(string& s, int pos) {
bool b1 = is_vowel(s[pos]);
bool b2 = is_vowel(s[pos-1]);
bool b3 = is_vowel(s[pos-2]);
//cerr << "checking: " << pos << " " << s.substr(pos-2, 3) << endl;
return (b1 && b2 && b3) || (!b1 && !b2 && !b3);
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
if(s.size() < 3){
cout << 0 << endl;
return 0;
}
ll init_seq = check_sequence(s, 2);
ll counter = init_seq;
ll current_seq_pos = init_seq == 0 ? 1 : 2;
for(ll i = 3; i < s.size(); ++i) {
//cerr << "Current_seq_pos: " << current_seq_pos << " counter " << counter << endl;
if(check_sequence(s, i)){
//cerr << "is new sequence, will add: " << i-2 << endl;
counter += i-1;
current_seq_pos = i;
} else {
//cerr << "is not a new sequence, will add: " << current_seq_pos-2+1 << endl;
counter += current_seq_pos-2+1;
}
}
cout << counter << 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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; inline bool is_vowel(char c){ return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } int check_sequence(string& s, int pos) { bool b1 = is_vowel(s[pos]); bool b2 = is_vowel(s[pos-1]); bool b3 = is_vowel(s[pos-2]); //cerr << "checking: " << pos << " " << s.substr(pos-2, 3) << endl; return (b1 && b2 && b3) || (!b1 && !b2 && !b3); } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; if(s.size() < 3){ cout << 0 << endl; return 0; } ll init_seq = check_sequence(s, 2); ll counter = init_seq; ll current_seq_pos = init_seq == 0 ? 1 : 2; for(ll i = 3; i < s.size(); ++i) { //cerr << "Current_seq_pos: " << current_seq_pos << " counter " << counter << endl; if(check_sequence(s, i)){ //cerr << "is new sequence, will add: " << i-2 << endl; counter += i-1; current_seq_pos = i; } else { //cerr << "is not a new sequence, will add: " << current_seq_pos-2+1 << endl; counter += current_seq_pos-2+1; } } cout << counter << endl; return 0; } |
English