#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ul; typedef unsigned int ui; #define s second #define f first #define PB push_back #define REP(x,y) for(int x=0;x<(y);x++) #define ROF(x,y) for(int x=(y);x>=0;x--) #define FOR(x,y,z) for(int x=(y);x<(z);x++) #define INT(x) int x;scanf("%d",&x) #define LL(x) long long x;scanf("%lld",&x) #define STR(x) string x; cin>>x; #define CZ(x) char x; cin >> x; int main(){ STR(x); ll ans = x.length(); ans*=(ans-1); ans/=2; int cnt=0; int p=0,k=0; for(unsigned int i=0;i<x.length();i++){ if(x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i] == 'u' || x[i] == 'y'){ if(cnt > 3)ans -= cnt-3; if(cnt >= 3)p = i-2; if(cnt > 0)cnt = 0; else cnt--; } else{ if(cnt < -3)ans -= abs(cnt)-3; if(cnt <= -3) p = i-2; if(cnt < 0) cnt = 0; else cnt++; } if(abs(cnt) == 3){ k = i; ans -= (k-p)*(k-p-1)/2; } } if(abs(cnt)<3){ k = x.length(); ans -= (k-p)*(k-p-1)/2; } else if(abs(cnt) == 3)ans--; else ans -= abs(cnt)-2; cout << 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 41 42 43 44 45 46 47 48 49 50 51 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ul; typedef unsigned int ui; #define s second #define f first #define PB push_back #define REP(x,y) for(int x=0;x<(y);x++) #define ROF(x,y) for(int x=(y);x>=0;x--) #define FOR(x,y,z) for(int x=(y);x<(z);x++) #define INT(x) int x;scanf("%d",&x) #define LL(x) long long x;scanf("%lld",&x) #define STR(x) string x; cin>>x; #define CZ(x) char x; cin >> x; int main(){ STR(x); ll ans = x.length(); ans*=(ans-1); ans/=2; int cnt=0; int p=0,k=0; for(unsigned int i=0;i<x.length();i++){ if(x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i] == 'u' || x[i] == 'y'){ if(cnt > 3)ans -= cnt-3; if(cnt >= 3)p = i-2; if(cnt > 0)cnt = 0; else cnt--; } else{ if(cnt < -3)ans -= abs(cnt)-3; if(cnt <= -3) p = i-2; if(cnt < 0) cnt = 0; else cnt++; } if(abs(cnt) == 3){ k = i; ans -= (k-p)*(k-p-1)/2; } } if(abs(cnt)<3){ k = x.length(); ans -= (k-p)*(k-p-1)/2; } else if(abs(cnt) == 3)ans--; else ans -= abs(cnt)-2; cout << ans; return 0; } |