#include <memory> #include <cstring> #include <stdio.h> #define LL long long #define MAX_LEN 200010 char buf[MAX_LEN]; LL d_count[MAX_LEN]; bool samogloska(char c) { return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'); } bool is_hard(char a, char b, char c) { bool ar = samogloska(a); bool br = samogloska(b); bool cr = samogloska(c); return ((ar && br && cr) || (!ar && !br && !cr)); } long long process(char* buf, int L) { if (L < 3) { return 0; } d_count[0] = 0; d_count[1] = 0; for (int i=2; i < L; i++) { d_count[i] = is_hard(buf[i], buf[i-1], buf[i-2]) ? (i-1) : d_count[i-1]; } //for (int i=0; i < L; i++) { // printf("%lld ", d_count[i]); //} //printf("\n"); LL res = 0; for (int i=0; i < L; i++) { res += d_count[i]; } return res; } int main() { scanf("%s", &buf); LL res = process(buf, strlen(buf)); printf("%lld\n", res); 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 | #include <memory> #include <cstring> #include <stdio.h> #define LL long long #define MAX_LEN 200010 char buf[MAX_LEN]; LL d_count[MAX_LEN]; bool samogloska(char c) { return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'); } bool is_hard(char a, char b, char c) { bool ar = samogloska(a); bool br = samogloska(b); bool cr = samogloska(c); return ((ar && br && cr) || (!ar && !br && !cr)); } long long process(char* buf, int L) { if (L < 3) { return 0; } d_count[0] = 0; d_count[1] = 0; for (int i=2; i < L; i++) { d_count[i] = is_hard(buf[i], buf[i-1], buf[i-2]) ? (i-1) : d_count[i-1]; } //for (int i=0; i < L; i++) { // printf("%lld ", d_count[i]); //} //printf("\n"); LL res = 0; for (int i=0; i < L; i++) { res += d_count[i]; } return res; } int main() { scanf("%s", &buf); LL res = process(buf, strlen(buf)); printf("%lld\n", res); return 0; } |