#include <iostream> #include <string> // funkcja sprawdza czy znak jest samogloska bool isvowel(const char& x) { if (x == 'a') return true; if (x == 'e') return true; if (x == 'i') return true; if (x == 'o') return true; if (x == 'u') return true; if (x == 'y') return true; return false; } int main() { std::string line; std::getline(std::cin, line); int l = 0, p = 0; //ramka int prev_lead = -1; //reprezentant poprzedniej ramki int i = 0; int count = 0; int n = line.length(); long long prefix_count = 0, post_count = 0; bool curr_is_vowel = false, prev_was_vowel = false; long long result = 0; if (n < 3) { std::cout << result; return 0; } while (i < n) { curr_is_vowel = isvowel(line[i]); if (curr_is_vowel) { if (!prev_was_vowel) { count = 0; l = i; } } else { if (prev_was_vowel) { count = 0; l = i; } } ++count; //jest ramka if (count == 3) { p = i; if (prev_lead == -1) prefix_count = l; else prefix_count = l - prev_lead; post_count = n - 1 - p; result += (1 + prefix_count + post_count + prefix_count * post_count); prev_lead = (l + p)/2; //reset dla nastepnej ramki --count; ++l; } prev_was_vowel = curr_is_vowel; ++i; } std::cout << result; 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 75 76 | #include <iostream> #include <string> // funkcja sprawdza czy znak jest samogloska bool isvowel(const char& x) { if (x == 'a') return true; if (x == 'e') return true; if (x == 'i') return true; if (x == 'o') return true; if (x == 'u') return true; if (x == 'y') return true; return false; } int main() { std::string line; std::getline(std::cin, line); int l = 0, p = 0; //ramka int prev_lead = -1; //reprezentant poprzedniej ramki int i = 0; int count = 0; int n = line.length(); long long prefix_count = 0, post_count = 0; bool curr_is_vowel = false, prev_was_vowel = false; long long result = 0; if (n < 3) { std::cout << result; return 0; } while (i < n) { curr_is_vowel = isvowel(line[i]); if (curr_is_vowel) { if (!prev_was_vowel) { count = 0; l = i; } } else { if (prev_was_vowel) { count = 0; l = i; } } ++count; //jest ramka if (count == 3) { p = i; if (prev_lead == -1) prefix_count = l; else prefix_count = l - prev_lead; post_count = n - 1 - p; result += (1 + prefix_count + post_count + prefix_count * post_count); prev_lead = (l + p)/2; //reset dla nastepnej ramki --count; ++l; } prev_was_vowel = curr_is_vowel; ++i; } std::cout << result; return 0; } |