#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[200001];
static inline bool sam(const int i) {
const char c = buf[i];
return c == 'a' || c == 'i' || c == 'e' || c == 'o' || c == 'u' || c == 'y';
}
int main() {
scanf("%s", buf);
const int len = strlen(buf);
long long int count = 0;
bool triple[3]; // last 3
int last = 1;
for (int i = 0; i < len && i < 2; i++)
triple[i] = sam(i);
for (int i = 2; i < len; ++i) {
triple[2] = sam(i);
if (triple[0] == triple[1] && triple[1] == triple[2]) {
const long long suffixes = len - i;
const int first = i - 2;
const int lastsec = last - 1;
const long long prefixes = first - lastsec + 1;
count += prefixes * suffixes;
last = i;
}
triple[0] = triple[1];
triple[1] = triple[2];
}
printf("%lld\n", count);
}
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 | #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char buf[200001]; static inline bool sam(const int i) { const char c = buf[i]; return c == 'a' || c == 'i' || c == 'e' || c == 'o' || c == 'u' || c == 'y'; } int main() { scanf("%s", buf); const int len = strlen(buf); long long int count = 0; bool triple[3]; // last 3 int last = 1; for (int i = 0; i < len && i < 2; i++) triple[i] = sam(i); for (int i = 2; i < len; ++i) { triple[2] = sam(i); if (triple[0] == triple[1] && triple[1] == triple[2]) { const long long suffixes = len - i; const int first = i - 2; const int lastsec = last - 1; const long long prefixes = first - lastsec + 1; count += prefixes * suffixes; last = i; } triple[0] = triple[1]; triple[1] = triple[2]; } printf("%lld\n", count); } |
English