#include <iostream>
using namespace std;
char c [7] = {'a', 'e', 'u', 'o', 'i', 'y'};
long long wynik;
string s;
int n;
int x[2];
pair<bool, bool> samogloska(char d)
{
for(int i=0; i<6; i++)
if(d==c[i])
return {1,0};
return {0,1};
}
bool ogarnij(int k, int j)
{
if(j!=n-2)
{
pair<bool, bool> q = samogloska(s[j+1]);
if(q.first==k)
return 0;
//cout<<"halo"<<q.first<<k<<endl;
}
int m, d, l;
m = x[k];
d = j - x[k]+1;
l = n-2-j;
if(d>=3)
{
// cout<<m<<' '<<d<<' '<<l<<endl;
wynik+=(d-3)*(m+l+2)+(m+1)*(l+1);
return 0;
}
else
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>s; s+='$';
n = s.size();
x[0]=x[1]=n;
for(int i=0; i<n; i++)
{
char m = s[i];
pair<bool, bool> p = samogloska(m);
if(x[p.first]==n)
x[p.first]=i;
x[p.second]=n;
ogarnij(p.first, i);
}
cout<<wynik;
}
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 | #include <iostream> using namespace std; char c [7] = {'a', 'e', 'u', 'o', 'i', 'y'}; long long wynik; string s; int n; int x[2]; pair<bool, bool> samogloska(char d) { for(int i=0; i<6; i++) if(d==c[i]) return {1,0}; return {0,1}; } bool ogarnij(int k, int j) { if(j!=n-2) { pair<bool, bool> q = samogloska(s[j+1]); if(q.first==k) return 0; //cout<<"halo"<<q.first<<k<<endl; } int m, d, l; m = x[k]; d = j - x[k]+1; l = n-2-j; if(d>=3) { // cout<<m<<' '<<d<<' '<<l<<endl; wynik+=(d-3)*(m+l+2)+(m+1)*(l+1); return 0; } else return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>s; s+='$'; n = s.size(); x[0]=x[1]=n; for(int i=0; i<n; i++) { char m = s[i]; pair<bool, bool> p = samogloska(m); if(x[p.first]==n) x[p.first]=i; x[p.second]=n; ogarnij(p.first, i); } cout<<wynik; } |
English