#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;
bool is_vowel(char c) {
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}
long long consume(int prev_start, int anchor_start, int anchor_end, int n) {
long long result = 0;
if (anchor_end - anchor_start >= 2) {
// cout << "found: " << prev_start << " " << anchor_start << " " << anchor_end << endl;
for( int x = prev_start; x < anchor_end - 1; x++) {
long long first_ok = max(anchor_start + 2, x+2);
long long last_ok = n-1;
long long count = last_ok - first_ok + 1;
if (count > 0){
// cout << "count = " << prev_start << " " << first_ok << " " <<last_ok<<" " << x << " " << count << endl;
result += count;
}
}
}
// int k = anchor_end - anchor_start + 1;
// if (k >= 3) {
// long long inner = (k-2)*(k-1) / 2;
// cout << "adding inner: " << inner << endl;
// result += inner;
// }
// int outer = anchor_end - anchor_start - 1;
// if (outer > 0){
// int at_end = n - anchor_end - 1;
// long long forward = outer * at_end;
// cout << "adding forward: " << at_end <<" " << forward << endl;
// result += forward;
// int at_start = anchor_start;
// long long backward = outer * at_start;
// cout << "adding backward: " << at_start <<" " << backward << endl;
// result += backward;
// }
return result;
}
long long compute(string &text) {
long long result = 0;
int anchor_start = 0;
int anchor_end = 0;
int prev_start = 0;
bool vowels = is_vowel(text[0]);
int n = text.length();
for (int i = 1; i < n; i++) {
bool is_v = is_vowel(text[i]);
if ((vowels && is_v) || (!vowels && !is_v)) {
anchor_end++;
} else {
result += consume(prev_start, anchor_start, anchor_end, n);
if (anchor_end - anchor_start >= 2) {
prev_start = max(0, anchor_end - 1);
}
anchor_start = i;
vowels = is_v;
anchor_end = i;
}
}
result += consume(prev_start, anchor_start, anchor_end, n);
return result;
}
int main() {
string text;
cin >> text;
cout << compute(text);
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <cstdio> #include <iostream> #include <cmath> #include <string> #include <sstream> #include <set> #include <algorithm> #include <deque> #include <map> using namespace std; bool is_vowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } long long consume(int prev_start, int anchor_start, int anchor_end, int n) { long long result = 0; if (anchor_end - anchor_start >= 2) { // cout << "found: " << prev_start << " " << anchor_start << " " << anchor_end << endl; for( int x = prev_start; x < anchor_end - 1; x++) { long long first_ok = max(anchor_start + 2, x+2); long long last_ok = n-1; long long count = last_ok - first_ok + 1; if (count > 0){ // cout << "count = " << prev_start << " " << first_ok << " " <<last_ok<<" " << x << " " << count << endl; result += count; } } } // int k = anchor_end - anchor_start + 1; // if (k >= 3) { // long long inner = (k-2)*(k-1) / 2; // cout << "adding inner: " << inner << endl; // result += inner; // } // int outer = anchor_end - anchor_start - 1; // if (outer > 0){ // int at_end = n - anchor_end - 1; // long long forward = outer * at_end; // cout << "adding forward: " << at_end <<" " << forward << endl; // result += forward; // int at_start = anchor_start; // long long backward = outer * at_start; // cout << "adding backward: " << at_start <<" " << backward << endl; // result += backward; // } return result; } long long compute(string &text) { long long result = 0; int anchor_start = 0; int anchor_end = 0; int prev_start = 0; bool vowels = is_vowel(text[0]); int n = text.length(); for (int i = 1; i < n; i++) { bool is_v = is_vowel(text[i]); if ((vowels && is_v) || (!vowels && !is_v)) { anchor_end++; } else { result += consume(prev_start, anchor_start, anchor_end, n); if (anchor_end - anchor_start >= 2) { prev_start = max(0, anchor_end - 1); } anchor_start = i; vowels = is_v; anchor_end = i; } } result += consume(prev_start, anchor_start, anchor_end, n); return result; } int main() { string text; cin >> text; cout << compute(text); return 0; } |
English