#include <iostream> #include <fstream> #include <vector> bool is_spolgloska(char c) { if( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' ) return false; return true; } void calculate(const std::vector<int> & starts, int len) { int previous = 0; size_t sum = 0; for(int start: starts) { sum += (start - previous + 1) * (len - (start + 2)); previous = start + 1; } std::cout << sum << std::endl; } void read(std::istream & str) { bool spolgloska[3]; size_t len = 0; int c; std::vector<int> starts; starts.reserve(200000); while( (c = str.get()) != -1 ) { if( c>='a' && c<='z' ) { if( len <= 2 ) { spolgloska[len] = is_spolgloska(c); } else { spolgloska[0] = spolgloska[1]; spolgloska[1] = spolgloska[2]; spolgloska[2] = is_spolgloska(c); } if( len >=2 ) { if( (spolgloska[0] == spolgloska[1]) && (spolgloska[1] == spolgloska[2]) ) { starts.push_back(len - 2); } } len += 1; } } calculate(starts, len); } int main() { read(std::cin); }
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 73 74 75 | #include <iostream> #include <fstream> #include <vector> bool is_spolgloska(char c) { if( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' ) return false; return true; } void calculate(const std::vector<int> & starts, int len) { int previous = 0; size_t sum = 0; for(int start: starts) { sum += (start - previous + 1) * (len - (start + 2)); previous = start + 1; } std::cout << sum << std::endl; } void read(std::istream & str) { bool spolgloska[3]; size_t len = 0; int c; std::vector<int> starts; starts.reserve(200000); while( (c = str.get()) != -1 ) { if( c>='a' && c<='z' ) { if( len <= 2 ) { spolgloska[len] = is_spolgloska(c); } else { spolgloska[0] = spolgloska[1]; spolgloska[1] = spolgloska[2]; spolgloska[2] = is_spolgloska(c); } if( len >=2 ) { if( (spolgloska[0] == spolgloska[1]) && (spolgloska[1] == spolgloska[2]) ) { starts.push_back(len - 2); } } len += 1; } } calculate(starts, len); } int main() { read(std::cin); } |