#include <iostream>
using namespace std;
bool is_vowel (char c) {
if (c == 'a') {
return true;
}
if (c == 'e') {
return true;
}
if (c == 'i') {
return true;
}
if (c == 'o') {
return true;
}
if (c == 'u') {
return true;
}
if (c == 'y') {
return true;
}
return false;
}
bool is_consonant (char c) {
return !is_vowel(c);
}
bool is_triple (int ind, string& a) {
if ( is_vowel(a[ind]) && is_vowel(a[ind+1]) && is_vowel(a[ind+2])) {
return true;
}
if ( is_consonant(a[ind]) && is_consonant(a[ind+1]) && is_consonant(a[ind+2])) {
return true;
}
return false;
}
int main() {
string a;
cin >> a;
long long res = 0;
int x = -1;
if (a.size() == 1 || a.size() == 2) {
cout << 0 << endl;
}
else {
for (int i = 0; i < a.size()-2; i++) {
if (is_triple(i, a)) {
res += (i-x) * (a.size()-i-2);
x = i;
}
}
cout << res << 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 | #include <iostream> using namespace std; bool is_vowel (char c) { if (c == 'a') { return true; } if (c == 'e') { return true; } if (c == 'i') { return true; } if (c == 'o') { return true; } if (c == 'u') { return true; } if (c == 'y') { return true; } return false; } bool is_consonant (char c) { return !is_vowel(c); } bool is_triple (int ind, string& a) { if ( is_vowel(a[ind]) && is_vowel(a[ind+1]) && is_vowel(a[ind+2])) { return true; } if ( is_consonant(a[ind]) && is_consonant(a[ind+1]) && is_consonant(a[ind+2])) { return true; } return false; } int main() { string a; cin >> a; long long res = 0; int x = -1; if (a.size() == 1 || a.size() == 2) { cout << 0 << endl; } else { for (int i = 0; i < a.size()-2; i++) { if (is_triple(i, a)) { res += (i-x) * (a.size()-i-2); x = i; } } cout << res << endl; } } |
English