#include <cstdio> #include <cstdlib> #include <cstring> #define VOVELS "aeiouy" bool vovel[256]; char str[200007]; bool can_advance(int i) { // printf("can_advance?(%i) [%c %c %c]\n", i, str[i], str[i - 1], str[i - 2]); return vovel[str[i]] != vovel[str[i - 1]] || vovel[str[i]] != vovel[str[i - 2]]; } int main() { for (char v : VOVELS) vovel[v] = true; scanf("%s", str); int len = (int) strlen(str); int j = 2; long long res = 0; for (int i = 0; i < len - 2; i++) { if (j < i + 2) j = i + 2; while (j < len && can_advance(j)) j++; // printf("%i - %i; += %i\n", i, j, len - j); res += len - j; } printf("%lli\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 | #include <cstdio> #include <cstdlib> #include <cstring> #define VOVELS "aeiouy" bool vovel[256]; char str[200007]; bool can_advance(int i) { // printf("can_advance?(%i) [%c %c %c]\n", i, str[i], str[i - 1], str[i - 2]); return vovel[str[i]] != vovel[str[i - 1]] || vovel[str[i]] != vovel[str[i - 2]]; } int main() { for (char v : VOVELS) vovel[v] = true; scanf("%s", str); int len = (int) strlen(str); int j = 2; long long res = 0; for (int i = 0; i < len - 2; i++) { if (j < i + 2) j = i + 2; while (j < len && can_advance(j)) j++; // printf("%i - %i; += %i\n", i, j, len - j); res += len - j; } printf("%lli\n", res); return 0; } |