#include<bits/stdc++.h> using namespace std; int result = 0, combo, l, r, pos; string input; void Decode(string in) { for (int i = 0; i < in.size(); ++i) { switch (in[i]) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': input[i] = '1'; break; default: input[i] = '0'; break; } } } bool FoundCombo() { for (int i = 0; i < input.size(); ++i) { combo = 1; while (input[i] == input[i + combo] && i + combo < input.size()) combo++; if (combo >= 3) { pos = i; return true; } i += combo - 1; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> input; Decode(input); while (true) { if (!FoundCombo()) break; l = pos; r = input.size() - pos - combo; result += ((combo - 1) * (combo - 2)) / 2 + (combo - 2) * (l + r) + l * r; input.erase(0, pos + combo - 2); } cout << result; 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 | #include<bits/stdc++.h> using namespace std; int result = 0, combo, l, r, pos; string input; void Decode(string in) { for (int i = 0; i < in.size(); ++i) { switch (in[i]) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': input[i] = '1'; break; default: input[i] = '0'; break; } } } bool FoundCombo() { for (int i = 0; i < input.size(); ++i) { combo = 1; while (input[i] == input[i + combo] && i + combo < input.size()) combo++; if (combo >= 3) { pos = i; return true; } i += combo - 1; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> input; Decode(input); while (true) { if (!FoundCombo()) break; l = pos; r = input.size() - pos - combo; result += ((combo - 1) * (combo - 2)) / 2 + (combo - 2) * (l + r) + l * r; input.erase(0, pos + combo - 2); } cout << result; return 0; } |