#include <iostream> #include <string> #include <algorithm> typedef long long integer; integer Samogloski = 0; integer Spolgloski = 0; std::string S; bool CzySamogloska(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } bool Dodaj(int i) { if (i >= S.size()) return false; if (CzySamogloska(S[i])) { if (Samogloski >= 2) return false; Samogloski++; Spolgloski = 0; } else { if (Spolgloski >= 2) return false; Samogloski = 0; Spolgloski++; } return true; } int main() { std::ios_base::sync_with_stdio(false); std::cin >> S; int left = 0, right = 0; integer res = 0; while (right < S.size()) { while (Dodaj(right)) right++; if (right != S.size()) { //TODO: zbic do O(1) while (left + 1 < right) { res += (right - left); left++; } Samogloski = Spolgloski = 0; Dodaj(left); } } res += ((right - left + 1LL)*(right - left)) / 2LL; integer r = (S.size()*(S.size() + 1) / 2LL) - res; std::cout << std::max(0LL,r); 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 | #include <iostream> #include <string> #include <algorithm> typedef long long integer; integer Samogloski = 0; integer Spolgloski = 0; std::string S; bool CzySamogloska(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } bool Dodaj(int i) { if (i >= S.size()) return false; if (CzySamogloska(S[i])) { if (Samogloski >= 2) return false; Samogloski++; Spolgloski = 0; } else { if (Spolgloski >= 2) return false; Samogloski = 0; Spolgloski++; } return true; } int main() { std::ios_base::sync_with_stdio(false); std::cin >> S; int left = 0, right = 0; integer res = 0; while (right < S.size()) { while (Dodaj(right)) right++; if (right != S.size()) { //TODO: zbic do O(1) while (left + 1 < right) { res += (right - left); left++; } Samogloski = Spolgloski = 0; Dodaj(left); } } res += ((right - left + 1LL)*(right - left)) / 2LL; integer r = (S.size()*(S.size() + 1) / 2LL) - res; std::cout << std::max(0LL,r); return 0; } |