#include<cstdio> #include<cstring> #include<vector> using namespace std; char in[200001]; vector<bool> B(200001); bool spol(char c) { if(c=='a' or c=='e' or c=='i' or c=='u' or c=='o' or c=='y') return false; return true; } long long po2(int n)//no prawie { return ((1LL*n)*(n+1))/2; } int main() { scanf("%s",in); int n=strlen(in); vector<int> pos; for(int i=0;i<n;i++) B[i]=spol(in[i]); for(int i=2;i<n;i++) { if(B[i]==B[i-1] and B[i]==B[i-2]) { pos.push_back(i); } } long long ans=po2(n); if(pos.size()!=0) { ans-=po2(pos[0]); for(int i=0;i<pos.size()-1;i++) { int l=pos[i+1]-pos[i]; ans-=po2(l+1); } ans-=po2(n-pos.back()+1); } ans+=pos.size(); printf("%lld\n",ans); }
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 | #include<cstdio> #include<cstring> #include<vector> using namespace std; char in[200001]; vector<bool> B(200001); bool spol(char c) { if(c=='a' or c=='e' or c=='i' or c=='u' or c=='o' or c=='y') return false; return true; } long long po2(int n)//no prawie { return ((1LL*n)*(n+1))/2; } int main() { scanf("%s",in); int n=strlen(in); vector<int> pos; for(int i=0;i<n;i++) B[i]=spol(in[i]); for(int i=2;i<n;i++) { if(B[i]==B[i-1] and B[i]==B[i-2]) { pos.push_back(i); } } long long ans=po2(n); if(pos.size()!=0) { ans-=po2(pos[0]); for(int i=0;i<pos.size()-1;i++) { int l=pos[i+1]-pos[i]; ans-=po2(l+1); } ans-=po2(n-pos.back()+1); } ans+=pos.size(); printf("%lld\n",ans); } |