#include <bits/stdc++.h> using namespace std; const int mx=2e5+4; char slow[mx]; int n; vector <char> sam = {'a', 'e', 'i', 'o', 'u', 'y'}; bool czy[mx]; vector <int> vec; long long ans; int main(){ scanf("%s",slow); n = strlen(slow); ans = ((long long)n*(long long)(n-1))/2LL; for(int i=0; i<n; i++){ for(auto x : sam){ if(slow[i] == x) czy[i] = true; } } czy[n]=czy[n-1]+1; vec.push_back(0); for(int i=0; i<n; i++){ if(czy[i] == czy[i-1] && czy[i] == czy[i+1]){ vec.push_back(i); } //printf("i %d %d\n", i, czy[i]); } vec.push_back(n-1); for(int i=0; i<(int)vec.size()-1; i++){ int x = vec[i], y = vec[i+1]; //printf(">%d %d\n",x, y); long long temp_n =(long long) (y-x+1); ans -= (temp_n*(temp_n-1))/2; } 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 37 38 39 40 | #include <bits/stdc++.h> using namespace std; const int mx=2e5+4; char slow[mx]; int n; vector <char> sam = {'a', 'e', 'i', 'o', 'u', 'y'}; bool czy[mx]; vector <int> vec; long long ans; int main(){ scanf("%s",slow); n = strlen(slow); ans = ((long long)n*(long long)(n-1))/2LL; for(int i=0; i<n; i++){ for(auto x : sam){ if(slow[i] == x) czy[i] = true; } } czy[n]=czy[n-1]+1; vec.push_back(0); for(int i=0; i<n; i++){ if(czy[i] == czy[i-1] && czy[i] == czy[i+1]){ vec.push_back(i); } //printf("i %d %d\n", i, czy[i]); } vec.push_back(n-1); for(int i=0; i<(int)vec.size()-1; i++){ int x = vec[i], y = vec[i+1]; //printf(">%d %d\n",x, y); long long temp_n =(long long) (y-x+1); ans -= (temp_n*(temp_n-1))/2; } printf("%lld\n",ans); return 0; } |