#include <bits/stdc++.h> using namespace std; #define MAXN 200007 char tab[MAXN]; long long result, up_to_now, last_good; bool bad_fragment(int i) { if (i < 2) return false; if (tab[i] == tab[i-1] && tab[i] == tab[i-2]){ return true; } return false; } void add_good_fragment(long long length) { result -= ((length + 1) * length) / 2; } int main() { scanf("%s", tab); int len = strlen(tab); result = (((long long)len)* (long long)(len + 1))/2; for(int i = 0; i < len; i++){ if (tab[i] == 'a' or tab[i] == 'e' or tab[i] == 'i' or tab[i] == 'o' or tab[i] == 'u' or tab[i] == 'y') { tab[i] = 1; } else { tab[i] = 0; } if (bad_fragment(i)){ add_good_fragment(i - last_good); result += 1; last_good = i - 1; } //printf("%lld\n", result); } add_good_fragment(len - last_good); printf("%lld\n", result); }
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 | #include <bits/stdc++.h> using namespace std; #define MAXN 200007 char tab[MAXN]; long long result, up_to_now, last_good; bool bad_fragment(int i) { if (i < 2) return false; if (tab[i] == tab[i-1] && tab[i] == tab[i-2]){ return true; } return false; } void add_good_fragment(long long length) { result -= ((length + 1) * length) / 2; } int main() { scanf("%s", tab); int len = strlen(tab); result = (((long long)len)* (long long)(len + 1))/2; for(int i = 0; i < len; i++){ if (tab[i] == 'a' or tab[i] == 'e' or tab[i] == 'i' or tab[i] == 'o' or tab[i] == 'u' or tab[i] == 'y') { tab[i] = 1; } else { tab[i] = 0; } if (bad_fragment(i)){ add_good_fragment(i - last_good); result += 1; last_good = i - 1; } //printf("%lld\n", result); } add_good_fragment(len - last_good); printf("%lld\n", result); } |