#include <iostream> #include <unordered_set> #include <string> using namespace std; bool is_speakable(const char& a, const char& b,const char& c) { unordered_set<char> conson = {'a','e','i','o','u','y'}; if(conson.find(a) == conson.end() and conson.find(b) == conson.end() and conson.find(c) == conson.end()){ return false; } if(conson.find(a) != conson.end() and conson.find(b) != conson.end() and conson.find(c) != conson.end()){ return false; } return true; } long long int count_string(const string& input, size_t start) { long long int ret = 0; while(true){ if((input.size() - start) < 3){ return ret; } if((input.size() - start) == 3){ int i = start; return ret + !is_speakable(input[i], input[i+1], input[i+2]); } for(size_t i = start, j = 0; i + 2 < input.size(); i++, j++){ if(!is_speakable(input[i], input[i+1], input[i+2])){ ret += (j + 1) * (input.size() - i - 2); start = i + 1; break; } if(i + 3 == input.size()){ return ret; } } } } int main (){ string ins; getline (cin,ins); cout << count_string(ins, 0) << endl; }
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 | #include <iostream> #include <unordered_set> #include <string> using namespace std; bool is_speakable(const char& a, const char& b,const char& c) { unordered_set<char> conson = {'a','e','i','o','u','y'}; if(conson.find(a) == conson.end() and conson.find(b) == conson.end() and conson.find(c) == conson.end()){ return false; } if(conson.find(a) != conson.end() and conson.find(b) != conson.end() and conson.find(c) != conson.end()){ return false; } return true; } long long int count_string(const string& input, size_t start) { long long int ret = 0; while(true){ if((input.size() - start) < 3){ return ret; } if((input.size() - start) == 3){ int i = start; return ret + !is_speakable(input[i], input[i+1], input[i+2]); } for(size_t i = start, j = 0; i + 2 < input.size(); i++, j++){ if(!is_speakable(input[i], input[i+1], input[i+2])){ ret += (j + 1) * (input.size() - i - 2); start = i + 1; break; } if(i + 3 == input.size()){ return ret; } } } } int main (){ string ins; getline (cin,ins); cout << count_string(ins, 0) << endl; } |