#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
ll licz(ll n){
n-=2;
if(n<=0){
return 0;
}
return (n+1)*n/2;
}
string s;
int samo(char c){
if(c=='a') return 1;
if(c=='e') return 1;
if(c=='o') return 1;
if(c=='u') return 1;
if(c=='i') return 1;
if(c=='y') return 1;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >>s;
int i,j,n,a,x;
n=s.size();
vector<pair<int,pair<int,int> > > vec;
vector<pair<int,int> > ve;
pair<int,int> pr;
pair<int,pair<int,int> > par;
for(i=0;i<n;i++){
x=samo(s[i]);
if(!vec.size() || vec[vec.size()-1].st!=x){
pr.st=i;
pr.nd=i;
par=mp(x,pr);
vec.pb(par);
}
else{
vec[vec.size()-1].nd.nd++;
}
}
for(i=0;i<vec.size();i++){
//cout <<vec[i].st <<" "<<vec[i].nd.st<<"-"<<vec[i].nd.nd <<"\n";
if(vec[i].nd.nd-vec[i].nd.st >= 2 ){
ve.pb(vec[i].nd);
}
}
ll wyn=licz(n);
if(ve.size()==0){
cout <<"0";
return 0;
}
for(i=0;i<ve.size()-1;i++){
wyn-=licz(ve[i+1].st-ve[i].nd+3);
}
wyn-=licz(ve[0].st+2);
wyn-=licz(n-ve[ve.size()-1].nd+1);
cout <<wyn;
}
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 | #include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; ll licz(ll n){ n-=2; if(n<=0){ return 0; } return (n+1)*n/2; } string s; int samo(char c){ if(c=='a') return 1; if(c=='e') return 1; if(c=='o') return 1; if(c=='u') return 1; if(c=='i') return 1; if(c=='y') return 1; return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >>s; int i,j,n,a,x; n=s.size(); vector<pair<int,pair<int,int> > > vec; vector<pair<int,int> > ve; pair<int,int> pr; pair<int,pair<int,int> > par; for(i=0;i<n;i++){ x=samo(s[i]); if(!vec.size() || vec[vec.size()-1].st!=x){ pr.st=i; pr.nd=i; par=mp(x,pr); vec.pb(par); } else{ vec[vec.size()-1].nd.nd++; } } for(i=0;i<vec.size();i++){ //cout <<vec[i].st <<" "<<vec[i].nd.st<<"-"<<vec[i].nd.nd <<"\n"; if(vec[i].nd.nd-vec[i].nd.st >= 2 ){ ve.pb(vec[i].nd); } } ll wyn=licz(n); if(ve.size()==0){ cout <<"0"; return 0; } for(i=0;i<ve.size()-1;i++){ wyn-=licz(ve[i+1].st-ve[i].nd+3); } wyn-=licz(ve[0].st+2); wyn-=licz(n-ve[ve.size()-1].nd+1); cout <<wyn; } |
English