#include <bits/stdc++.h> using namespace std; const int N = 200005, ALPHA = 256; const char vowels[] = {'a', 'e', 'i', 'o', 'u', 'y'}; char wish[N]; bool isVowel[ALPHA]; bool isBad(int a, int b, int c) { return (isVowel[a] && isVowel[b] && isVowel[c]) || (!isVowel[a] && !isVowel[b] && !isVowel[c]); } int main() { for (int vowel : vowels) { isVowel[vowel] = true; } scanf("%s", &wish[1]); int n = strlen(wish + 1); long long ans = 0; int lastBad = 0; for (int i = 3; i <= n; i++) { if (isBad(wish[i], wish[i - 1], wish[i - 2])) { lastBad = i - 2; } ans += lastBad; } printf("%lld\n", ans); 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 | #include <bits/stdc++.h> using namespace std; const int N = 200005, ALPHA = 256; const char vowels[] = {'a', 'e', 'i', 'o', 'u', 'y'}; char wish[N]; bool isVowel[ALPHA]; bool isBad(int a, int b, int c) { return (isVowel[a] && isVowel[b] && isVowel[c]) || (!isVowel[a] && !isVowel[b] && !isVowel[c]); } int main() { for (int vowel : vowels) { isVowel[vowel] = true; } scanf("%s", &wish[1]); int n = strlen(wish + 1); long long ans = 0; int lastBad = 0; for (int i = 3; i <= n; i++) { if (isBad(wish[i], wish[i - 1], wish[i - 2])) { lastBad = i - 2; } ans += lastBad; } printf("%lld\n", ans); return 0; } |