#include <stdio.h>
#include <string.h>
void mapLettersToZerosAndOnes(char* buf, const int length)
{
for (int i = 0; i < length; ++i) {
buf[i] = buf[i] == 'a' || buf[i] == 'e' || buf[i] == 'i' || buf[i] == 'o' || buf[i] == 'u' || buf[i] == 'y';
}
}
long long int count(const long long int length, const long long int beginningOfLastThree, const long long int from, const long long int to)
{
if (beginningOfLastThree + 1 == from) {
return length - to;
} else {
return (length - to) * (from - beginningOfLastThree);
}
}
long long int count(const char* buf, const int length)
{
int zerosCount = (buf[0] == 0) + (buf[1] == 0) + (buf[2] == 0);
int onesCount = (buf[0] == 1) + (buf[1] == 1) + (buf[2] == 1);
int beginningOfLastThree = -1;
long long int result = 0;
if (zerosCount == 3 || onesCount == 3) {
result += count(length, beginningOfLastThree, 0, 2);
beginningOfLastThree = 0;
}
for (int i = 3; i < length; ++i) {
if (buf[i] == 0) {
zerosCount++;
} else {
onesCount++;
}
if (buf[i - 3] == 0) {
zerosCount--;
} else {
onesCount--;
}
if (zerosCount == 3 || onesCount == 3) {
result += count(length, beginningOfLastThree, i - 2, i);
beginningOfLastThree = i - 2;
}
}
return result;
}
int main()
{
char buf[200010];
scanf("%s", buf);
const int length = static_cast<int>(strlen(buf));
mapLettersToZerosAndOnes(buf, length);
printf("%lld\n", count(buf, length));
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 | #include <stdio.h> #include <string.h> void mapLettersToZerosAndOnes(char* buf, const int length) { for (int i = 0; i < length; ++i) { buf[i] = buf[i] == 'a' || buf[i] == 'e' || buf[i] == 'i' || buf[i] == 'o' || buf[i] == 'u' || buf[i] == 'y'; } } long long int count(const long long int length, const long long int beginningOfLastThree, const long long int from, const long long int to) { if (beginningOfLastThree + 1 == from) { return length - to; } else { return (length - to) * (from - beginningOfLastThree); } } long long int count(const char* buf, const int length) { int zerosCount = (buf[0] == 0) + (buf[1] == 0) + (buf[2] == 0); int onesCount = (buf[0] == 1) + (buf[1] == 1) + (buf[2] == 1); int beginningOfLastThree = -1; long long int result = 0; if (zerosCount == 3 || onesCount == 3) { result += count(length, beginningOfLastThree, 0, 2); beginningOfLastThree = 0; } for (int i = 3; i < length; ++i) { if (buf[i] == 0) { zerosCount++; } else { onesCount++; } if (buf[i - 3] == 0) { zerosCount--; } else { onesCount--; } if (zerosCount == 3 || onesCount == 3) { result += count(length, beginningOfLastThree, i - 2, i); beginningOfLastThree = i - 2; } } return result; } int main() { char buf[200010]; scanf("%s", buf); const int length = static_cast<int>(strlen(buf)); mapLettersToZerosAndOnes(buf, length); printf("%lld\n", count(buf, length)); return 0; } |
English