#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; string VOWELS = "aeiouy"; bool is_vowel(char c){ return VOWELS.find(c) != std::string::npos; } void print_vec(vector<long> & v) { for(int i = 0; i < v.size(); i++) { cout << v.at(i) << " "; } cout << endl; } int main() { string input; cin >> input; long size = input.length(); long curr_vow = 0; long curr_con = 0; vector<long> ind; for (long i = 0; i < size; i++) { if (is_vowel(input[i])) { curr_vow = min(3L, curr_vow + 1); curr_con = 0; } else { curr_con = min(3L, curr_con + 1); curr_vow = 0; } if ((curr_con == 3) or (curr_vow == 3)) { ind.push_back(i - 2); } } // print_vec(ind); long prev = -1; long acc = 0; long left, right; for(long i = 0; i < ind.size(); i++) { if (prev == -1) { left = ind.at(i); } else { left = ind.at(i) - prev - 1; } right = size - ind.at(i) - 3; prev = ind.at(i); // cout << left << " " << right << " " << prev << endl; if ((left == 0) and (right > 0)) { acc += right + 1; continue; } if ((right == 0) and (left > 0)) { acc += left + 1; continue; } if ((left == 0) and (right == 0)) { acc += 1; continue; } acc += (left + 1) * (right + 1); } cout << acc << 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; string VOWELS = "aeiouy"; bool is_vowel(char c){ return VOWELS.find(c) != std::string::npos; } void print_vec(vector<long> & v) { for(int i = 0; i < v.size(); i++) { cout << v.at(i) << " "; } cout << endl; } int main() { string input; cin >> input; long size = input.length(); long curr_vow = 0; long curr_con = 0; vector<long> ind; for (long i = 0; i < size; i++) { if (is_vowel(input[i])) { curr_vow = min(3L, curr_vow + 1); curr_con = 0; } else { curr_con = min(3L, curr_con + 1); curr_vow = 0; } if ((curr_con == 3) or (curr_vow == 3)) { ind.push_back(i - 2); } } // print_vec(ind); long prev = -1; long acc = 0; long left, right; for(long i = 0; i < ind.size(); i++) { if (prev == -1) { left = ind.at(i); } else { left = ind.at(i) - prev - 1; } right = size - ind.at(i) - 3; prev = ind.at(i); // cout << left << " " << right << " " << prev << endl; if ((left == 0) and (right > 0)) { acc += right + 1; continue; } if ((right == 0) and (left > 0)) { acc += left + 1; continue; } if ((left == 0) and (right == 0)) { acc += 1; continue; } acc += (left + 1) * (right + 1); } cout << acc << endl; return 0; } |