#include <iostream> #include <vector> #include <cmath> #include <set> #include <fstream> #include <string> #include <fstream> using ull = unsigned long long; ull komb(ull n) { return (n + n*n)/2; } using ulls = std::vector<ull>; std::set<char> samogloski = {'a', 'e', 'i', 'o', 'u', 'y'}; int isSamo(char a) { if (samogloski.count(a) >0) return 1; return 0; } bool isSame(std::vector<int> const& line, int n) { if(n+2 >= line.size()) return false; int count = 0; for(std::size_t i = n; i<n+3; ++i) count += line[i]; return count == 3 || count == 0; } ull countHard(std::vector<int> const& line) { ull count = 0; std::size_t last = -1; for (std::size_t i = 0; i<line.size();++i) { if (!isSame(line, i)) continue; int left = i-(last+1)+1; if (last == -1) left = i+1; int right = line.size() - i - 2; count += left*right; last = i; } return count; } int main() { std::string stream; std::cin >> stream; std::vector<int> line; for (char a : stream) line.push_back(isSamo(a)); std::cout << countHard(line) << std::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 73 74 | #include <iostream> #include <vector> #include <cmath> #include <set> #include <fstream> #include <string> #include <fstream> using ull = unsigned long long; ull komb(ull n) { return (n + n*n)/2; } using ulls = std::vector<ull>; std::set<char> samogloski = {'a', 'e', 'i', 'o', 'u', 'y'}; int isSamo(char a) { if (samogloski.count(a) >0) return 1; return 0; } bool isSame(std::vector<int> const& line, int n) { if(n+2 >= line.size()) return false; int count = 0; for(std::size_t i = n; i<n+3; ++i) count += line[i]; return count == 3 || count == 0; } ull countHard(std::vector<int> const& line) { ull count = 0; std::size_t last = -1; for (std::size_t i = 0; i<line.size();++i) { if (!isSame(line, i)) continue; int left = i-(last+1)+1; if (last == -1) left = i+1; int right = line.size() - i - 2; count += left*right; last = i; } return count; } int main() { std::string stream; std::cin >> stream; std::vector<int> line; for (char a : stream) line.push_back(isSamo(a)); std::cout << countHard(line) << std::endl; return 0; } |