#include <iostream> #include <vector> using namespace std; bool isSamo(char c) { return c == 'a' || c == 'e' || c == 'y' || c == 'u' || c == 'o' || c == 'i'; } int n; vector<bool> v; inline int last0(int i) { return !v[i-1] + !v[i-2]; } inline int last1(int i) { return v[i-1] + v[i-2]; } int enchunk() { if (n < 3) return 0; // cerr << "input: "; // for (bool c : v) // cerr << c; // cerr << "\n\n"; int out = 0; for (int i = 2; i < n; ++i) { // cerr << "Processing: " << v[i] << " (id: " << i << ")\t last0 " << last0(i) << ", last1 " << last1(i) << "\n"; int chunksize = 2; if (((last1(i) > 1) && (v[i] == 0)) // 110 || ((last0(i) > 1) && (v[i] == 1)) // 001 || (v[i-2] + v[i-1] == 1) // 01x / 10x, beginning only ) { // count starting // cerr << "trigger at " << i << "\n"; for (; !((last1(i) == 2) && (v[i] == 1)) && !((last0(i) == 2) && v[i] == 0) && i < n; ++i) { chunksize += 1; } // cerr << "stop at " << i << ". Got chunk size: " << chunksize << "\n"; int combs = (chunksize * (chunksize - 1)) / 2 - (chunksize - 1); out += combs; if (i == n) return out; // i--; } } return out; } int main () { string s; cin >> s; n = s.size(); for (int i = 0; i < n; ++i) { v.push_back(isSamo(s[i])); } int twos = (n-1); int upthrees = enchunk(); // cerr << "\nenchunked: " << upthrees << "\n"; cout << ((n * (n-1)/2)) - (twos + upthrees) << "\n"; }
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 | #include <iostream> #include <vector> using namespace std; bool isSamo(char c) { return c == 'a' || c == 'e' || c == 'y' || c == 'u' || c == 'o' || c == 'i'; } int n; vector<bool> v; inline int last0(int i) { return !v[i-1] + !v[i-2]; } inline int last1(int i) { return v[i-1] + v[i-2]; } int enchunk() { if (n < 3) return 0; // cerr << "input: "; // for (bool c : v) // cerr << c; // cerr << "\n\n"; int out = 0; for (int i = 2; i < n; ++i) { // cerr << "Processing: " << v[i] << " (id: " << i << ")\t last0 " << last0(i) << ", last1 " << last1(i) << "\n"; int chunksize = 2; if (((last1(i) > 1) && (v[i] == 0)) // 110 || ((last0(i) > 1) && (v[i] == 1)) // 001 || (v[i-2] + v[i-1] == 1) // 01x / 10x, beginning only ) { // count starting // cerr << "trigger at " << i << "\n"; for (; !((last1(i) == 2) && (v[i] == 1)) && !((last0(i) == 2) && v[i] == 0) && i < n; ++i) { chunksize += 1; } // cerr << "stop at " << i << ". Got chunk size: " << chunksize << "\n"; int combs = (chunksize * (chunksize - 1)) / 2 - (chunksize - 1); out += combs; if (i == n) return out; // i--; } } return out; } int main () { string s; cin >> s; n = s.size(); for (int i = 0; i < n; ++i) { v.push_back(isSamo(s[i])); } int twos = (n-1); int upthrees = enchunk(); // cerr << "\nenchunked: " << upthrees << "\n"; cout << ((n * (n-1)/2)) - (twos + upthrees) << "\n"; } |