#include <iostream> #define ll long long using namespace std; ll computeAll(ll x) { return x*(x+1)/2; } ll le2(ll x) { return 2*x - 1; } ll gt2(ll x) { return computeAll(x) - le2(x); } int cnv(char c) { bool isVowel = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; return isVowel?1:0; } ll solve(string& s) { int n = s.length(); ll pos = le2(n); int start = 0; int prev = cnv(s[0]); int cnt = 1; bool d = false; for(int i=1;i<n;i++) { int cur = cnv(s[i]); if(cur == prev) { cnt++; if(cnt == 3) { d = true; pos += gt2(i - start); } } else { prev = cur; cnt = 1; if(d) { d = false; start = i-2; } } } if(!d) { pos += gt2(n - start); } return computeAll(n) - pos; } int main(int argc, char** argv) { ios::sync_with_stdio(false); string s; cin>>s; cout<<solve(s)<<endl; 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 60 61 62 63 64 65 | #include <iostream> #define ll long long using namespace std; ll computeAll(ll x) { return x*(x+1)/2; } ll le2(ll x) { return 2*x - 1; } ll gt2(ll x) { return computeAll(x) - le2(x); } int cnv(char c) { bool isVowel = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; return isVowel?1:0; } ll solve(string& s) { int n = s.length(); ll pos = le2(n); int start = 0; int prev = cnv(s[0]); int cnt = 1; bool d = false; for(int i=1;i<n;i++) { int cur = cnv(s[i]); if(cur == prev) { cnt++; if(cnt == 3) { d = true; pos += gt2(i - start); } } else { prev = cur; cnt = 1; if(d) { d = false; start = i-2; } } } if(!d) { pos += gt2(n - start); } return computeAll(n) - pos; } int main(int argc, char** argv) { ios::sync_with_stdio(false); string s; cin>>s; cout<<solve(s)<<endl; return 0; } |