#include <iostream> #include <cstring> char buf[200001]; int is_a_vowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } long long count_difficulties(char *p, char *last_difficulty, int count, int len) { long long mid = (1LL*(count-1)*(count-2)) >> 1; long long left = (p-last_difficulty)-count; long right = len - (p-buf); // std::cout << count << " ! " << left << " : " << mid << " : " << right << std::endl; return (mid + (count-2)*(left+right) + left*right); } int main() { char *p = buf; char *last_difficulty = buf; long long res = 0LL; int count = 0; int is_last_char_a_vowel = 0; std::cin >> buf; int len = std::strlen(buf); while(*p) { if(is_a_vowel(*p)) { if(is_last_char_a_vowel) { count++; } else { if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } is_last_char_a_vowel = 1; count = 1; } } else { // not a vowel if(is_last_char_a_vowel) { if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } is_last_char_a_vowel = 0; count = 1; } else { count++; } } p++; } if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } std::cout << res << 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 | #include <iostream> #include <cstring> char buf[200001]; int is_a_vowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } long long count_difficulties(char *p, char *last_difficulty, int count, int len) { long long mid = (1LL*(count-1)*(count-2)) >> 1; long long left = (p-last_difficulty)-count; long right = len - (p-buf); // std::cout << count << " ! " << left << " : " << mid << " : " << right << std::endl; return (mid + (count-2)*(left+right) + left*right); } int main() { char *p = buf; char *last_difficulty = buf; long long res = 0LL; int count = 0; int is_last_char_a_vowel = 0; std::cin >> buf; int len = std::strlen(buf); while(*p) { if(is_a_vowel(*p)) { if(is_last_char_a_vowel) { count++; } else { if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } is_last_char_a_vowel = 1; count = 1; } } else { // not a vowel if(is_last_char_a_vowel) { if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } is_last_char_a_vowel = 0; count = 1; } else { count++; } } p++; } if(count > 2) { res += count_difficulties(p, last_difficulty, count, len); last_difficulty = p-2; } std::cout << res << std::endl; return 0; } |