#include <cstdio> #include <cstring> #include <vector> inline bool vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } const int MX = 2e5 + 7; char buffer[MX]; std::vector<int> vowels; int n; int main() { scanf("%s", buffer + 1); n = strlen(buffer + 1); vowels.push_back(1); for (int i = 1; i <= n - 2; ++i) { if (vowel(buffer[i]) && vowel(buffer[i + 1]) && vowel(buffer[i + 2])) { //printf("push back %d\n", i); vowels.push_back(i + 1); } if (!vowel(buffer[i]) && !vowel(buffer[i + 1]) && !vowel(buffer[i + 2])) { //printf("push back %d\n", i); vowels.push_back(i + 1); } } vowels.push_back(n); long long int result = 0; for (int i = 0; i < static_cast<int>(vowels.size()) - 1; ++i) { long long int cn = vowels.at(i + 1) - vowels.at(i) + 1; //printf("%d - %d :: %lld %lld\n", vowels.at(i), vowels.at(i + 1), cn, cn * (cn + 1LL) / 2LL); result += cn * (cn + 1LL) / 2LL; } /* for (auto it : vowels) { printf("%d ", it); } puts(""); */ long long int cn = n; result -= static_cast<long long int>(vowels.size() - 2); //printf("good: %lld\n", result); //printf("all: %lld\n", cn * (cn + 1LL) / 2LL); result = cn * (cn + 1LL) / 2LL - result; //printf("bad: %lld\n", result); printf("%lld\n", 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 | #include <cstdio> #include <cstring> #include <vector> inline bool vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } const int MX = 2e5 + 7; char buffer[MX]; std::vector<int> vowels; int n; int main() { scanf("%s", buffer + 1); n = strlen(buffer + 1); vowels.push_back(1); for (int i = 1; i <= n - 2; ++i) { if (vowel(buffer[i]) && vowel(buffer[i + 1]) && vowel(buffer[i + 2])) { //printf("push back %d\n", i); vowels.push_back(i + 1); } if (!vowel(buffer[i]) && !vowel(buffer[i + 1]) && !vowel(buffer[i + 2])) { //printf("push back %d\n", i); vowels.push_back(i + 1); } } vowels.push_back(n); long long int result = 0; for (int i = 0; i < static_cast<int>(vowels.size()) - 1; ++i) { long long int cn = vowels.at(i + 1) - vowels.at(i) + 1; //printf("%d - %d :: %lld %lld\n", vowels.at(i), vowels.at(i + 1), cn, cn * (cn + 1LL) / 2LL); result += cn * (cn + 1LL) / 2LL; } /* for (auto it : vowels) { printf("%d ", it); } puts(""); */ long long int cn = n; result -= static_cast<long long int>(vowels.size() - 2); //printf("good: %lld\n", result); //printf("all: %lld\n", cn * (cn + 1LL) / 2LL); result = cn * (cn + 1LL) / 2LL - result; //printf("bad: %lld\n", result); printf("%lld\n", result); return 0; } |