#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : a)
#define SZ(i) ((int)(i).size())
#define X first
#define Y second
#define PR std::pair
#define PII std::pair<int, int>
#define MP std::make_pair
#define ll long long
#define VI std::vector<int>
std::string str;
bool samo(char ch){
return ch == 'a' || ch == 'e' || ch == 'o' || ch == 'y' || ch == 'u' || ch =='i';
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cin >> str;
std::vector<bool> bad(SZ(str));
int last = 0;
FOR(i, SZ(str)){
if(samo(str[i])){
if(last < 0) last = 0;
last++;
}else{
if(last > 0) last = 0;
last--;
}
if(std::abs(last) >= 3) bad[i] = true;
}
VI next(SZ(str)+1);
next[SZ(str)] = SZ(str);
for(int i = SZ(str)-1; i >= 0; --i){
next[i] = next[i+1];
if(bad[i]) next[i] = i;
}
ll ans = 0;
FOR(i, SZ(str)-2){
int nxt = next[i+2];
ans += nxt-i;
}
if(SZ(str) >= 1) ans += 1;
if(SZ(str) >= 2) ans += 2;
std::cout << 1ll*SZ(str)*(SZ(str)+1ll)/2ll-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> #define FOR(i, n) for(int i = 0; i < (n); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define TRAV(i, a) for(auto &i : a) #define SZ(i) ((int)(i).size()) #define X first #define Y second #define PR std::pair #define PII std::pair<int, int> #define MP std::make_pair #define ll long long #define VI std::vector<int> std::string str; bool samo(char ch){ return ch == 'a' || ch == 'e' || ch == 'o' || ch == 'y' || ch == 'u' || ch =='i'; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cin >> str; std::vector<bool> bad(SZ(str)); int last = 0; FOR(i, SZ(str)){ if(samo(str[i])){ if(last < 0) last = 0; last++; }else{ if(last > 0) last = 0; last--; } if(std::abs(last) >= 3) bad[i] = true; } VI next(SZ(str)+1); next[SZ(str)] = SZ(str); for(int i = SZ(str)-1; i >= 0; --i){ next[i] = next[i+1]; if(bad[i]) next[i] = i; } ll ans = 0; FOR(i, SZ(str)-2){ int nxt = next[i+2]; ans += nxt-i; } if(SZ(str) >= 1) ans += 1; if(SZ(str) >= 2) ans += 2; std::cout << 1ll*SZ(str)*(SZ(str)+1ll)/2ll-ans; return 0; } |
English