#include <bits/stdc++.h> using namespace std; string s; vector <long long> cent; char vowels[6] = {'a','e','i','o','u','y'}; long long cnt = 0; void obtCenters(){ for(int a = 0; a < s.size(); a++){ bool vow = 0; for(int b = 0; b < 6; b++){ if(s[a] == vowels[b]){ vow = 1; } } if(vow) s[a] = 'a'; else s[a] = 'b'; } cent.push_back(0); for(int a = 2; a < s.size(); a++){ if(s[a] == s[a-1] && s[a] == s[a-2]){ cent.push_back(a-1); } } cent.push_back(s.size()-1); } void calc(){ long long n = s.size(); long long base = (n*(n+1))/2; base += (cent.size()-2); cnt += base; for(int a = 0; a < cent.size()-1; a++){ long long k = cent[a+1]-cent[a]+1; long long safe = (k*(k+1))/2; cnt -= safe; } cout << cnt << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> s; obtCenters(); calc(); }
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 | #include <bits/stdc++.h> using namespace std; string s; vector <long long> cent; char vowels[6] = {'a','e','i','o','u','y'}; long long cnt = 0; void obtCenters(){ for(int a = 0; a < s.size(); a++){ bool vow = 0; for(int b = 0; b < 6; b++){ if(s[a] == vowels[b]){ vow = 1; } } if(vow) s[a] = 'a'; else s[a] = 'b'; } cent.push_back(0); for(int a = 2; a < s.size(); a++){ if(s[a] == s[a-1] && s[a] == s[a-2]){ cent.push_back(a-1); } } cent.push_back(s.size()-1); } void calc(){ long long n = s.size(); long long base = (n*(n+1))/2; base += (cent.size()-2); cnt += base; for(int a = 0; a < cent.size()-1; a++){ long long k = cent[a+1]-cent[a]+1; long long safe = (k*(k+1))/2; cnt -= safe; } cout << cnt << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> s; obtCenters(); calc(); } |