#include <cctype> #include <cstdio> #include <cstring> //#define FORMAT "%I64d\n" // mingw #define FORMAT "%lld\n" // linux #define BUFSIZE 256*1024 #define MAX_N 200000 char tekst[BUFSIZE]; int n; bool IsVowel(char c) { return strchr("aeiouy", c) != NULL; } long long CountHardFragments() { long long result = 0; int start = 0; bool last = false; int runCount = 0; for (int i = 0; i < n; i++) { bool current = IsVowel(tekst[i]); if (current == last) { ++runCount; if (runCount >= 3) { int hardStart = i - 2; long long front = hardStart - start + 1; int back = n - i; result += front * back; start = hardStart + 1; } } else { last = current; runCount = 1; } } return result; } int main() { if (fgets(tekst, BUFSIZE, stdin) == NULL) { return 1; } n = 0; for (int i = 0; tekst[i] != '\0'; i++) { if (!isspace(tekst[i])) { tekst[n] = tekst[i]; ++n; } } tekst[n] = '\0'; long long result = CountHardFragments(); printf(FORMAT, 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 | #include <cctype> #include <cstdio> #include <cstring> //#define FORMAT "%I64d\n" // mingw #define FORMAT "%lld\n" // linux #define BUFSIZE 256*1024 #define MAX_N 200000 char tekst[BUFSIZE]; int n; bool IsVowel(char c) { return strchr("aeiouy", c) != NULL; } long long CountHardFragments() { long long result = 0; int start = 0; bool last = false; int runCount = 0; for (int i = 0; i < n; i++) { bool current = IsVowel(tekst[i]); if (current == last) { ++runCount; if (runCount >= 3) { int hardStart = i - 2; long long front = hardStart - start + 1; int back = n - i; result += front * back; start = hardStart + 1; } } else { last = current; runCount = 1; } } return result; } int main() { if (fgets(tekst, BUFSIZE, stdin) == NULL) { return 1; } n = 0; for (int i = 0; tekst[i] != '\0'; i++) { if (!isspace(tekst[i])) { tekst[n] = tekst[i]; ++n; } } tekst[n] = '\0'; long long result = CountHardFragments(); printf(FORMAT, result); return 0; } |