#include <iostream> #include <vector> #include <string> #define SIZE 200200 typedef long long LL; using namespace std; int main() { vector <LL> intervals; string input; cin >> input; LL len = input.size(); bool consonant[SIZE]; for(int i = 0; i < len; ++i) { if(input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u' || input[i] == 'y') { consonant[i] = false; } else { consonant[i] = true; } } // cout << len << endl; // for(int i = 0; i < len; ++i) { // cout << consonant[i]; // } cout << endl; LL easy = 2; LL sum_overlaps = 0; for(int i = 2; i < len; ++i) { if(consonant[i-2] == consonant[i-1] && consonant[i-1] == consonant[i]) { ++sum_overlaps; if(easy > 0) { intervals.push_back(easy); } easy = 2; } else { ++easy; } } if(easy > 0) { intervals.push_back(easy); } // for(auto e: intervals) { // cout << e << " "; // } cout << endl; // cout << sum_overlaps << endl; // cout << "All intervals: " << len*(len-1)/2+len << endl; LL res = len*(len-1)/2+len; for(auto e: intervals) { // cout << e*(e-1)/2+e << " "; res -= e*(e-1)/2+e; } //cout << endl; // cout << "Result: " << res+sum_overlaps << endl; cout << res+sum_overlaps << 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 | #include <iostream> #include <vector> #include <string> #define SIZE 200200 typedef long long LL; using namespace std; int main() { vector <LL> intervals; string input; cin >> input; LL len = input.size(); bool consonant[SIZE]; for(int i = 0; i < len; ++i) { if(input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u' || input[i] == 'y') { consonant[i] = false; } else { consonant[i] = true; } } // cout << len << endl; // for(int i = 0; i < len; ++i) { // cout << consonant[i]; // } cout << endl; LL easy = 2; LL sum_overlaps = 0; for(int i = 2; i < len; ++i) { if(consonant[i-2] == consonant[i-1] && consonant[i-1] == consonant[i]) { ++sum_overlaps; if(easy > 0) { intervals.push_back(easy); } easy = 2; } else { ++easy; } } if(easy > 0) { intervals.push_back(easy); } // for(auto e: intervals) { // cout << e << " "; // } cout << endl; // cout << sum_overlaps << endl; // cout << "All intervals: " << len*(len-1)/2+len << endl; LL res = len*(len-1)/2+len; for(auto e: intervals) { // cout << e*(e-1)/2+e << " "; res -= e*(e-1)/2+e; } //cout << endl; // cout << "Result: " << res+sum_overlaps << endl; cout << res+sum_overlaps << endl; return 0; } |