#include <iostream> #include <vector> bool isF(const char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return true; return false; } int main () { std::string s; std::cin >> s; std::vector<unsigned long long> v(s.size(), 0); v[0] = 1; if (s.size() > 1) v[1] = 2; for (int i = 2; i < s.size(); ++i) { if (isF(s[i]) && isF(s[i - 1]) && isF(s[i - 2])) v[i] = 2; else if (!isF(s[i]) && !isF(s[i - 1]) && !isF(s[i - 2])) v[i] = 2; else v[i] = v[i - 1] + 1; } unsigned long long n = s.size(); unsigned long long result = n * (n + 1) / 2; for (auto i : v) { result -= i; } std::cout << result << 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 | #include <iostream> #include <vector> bool isF(const char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return true; return false; } int main () { std::string s; std::cin >> s; std::vector<unsigned long long> v(s.size(), 0); v[0] = 1; if (s.size() > 1) v[1] = 2; for (int i = 2; i < s.size(); ++i) { if (isF(s[i]) && isF(s[i - 1]) && isF(s[i - 2])) v[i] = 2; else if (!isF(s[i]) && !isF(s[i - 1]) && !isF(s[i - 2])) v[i] = 2; else v[i] = v[i - 1] + 1; } unsigned long long n = s.size(); unsigned long long result = n * (n + 1) / 2; for (auto i : v) { result -= i; } std::cout << result << std::endl; return 0; } |