#include <bits/stdc++.h> using namespace std; typedef long long LL; char sam[6] = {'a', 'e', 'y', 'u', 'i', 'o'}; string s; bool check(int i){ int r = 0; bool ok=false; for(int j=0; j<3; ++j){ for(int k=0; k<6; k++){ if(s[i+j] == sam[k]){ ok=true; r++; break; } } if(ok){ ok=false; } else{ r--; } } if (r==3 || r==-3) return true; return false; } int main(){ ios::sync_with_stdio(0); cin>>s; int last = -1; LL res = 0; for(unsigned i=0; i<s.size()-2; ++i){ if(check(i)){ res += LL(i-last) * LL(s.size()-i-2); last = i; } } cout<<res<<"\n"; 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 | #include <bits/stdc++.h> using namespace std; typedef long long LL; char sam[6] = {'a', 'e', 'y', 'u', 'i', 'o'}; string s; bool check(int i){ int r = 0; bool ok=false; for(int j=0; j<3; ++j){ for(int k=0; k<6; k++){ if(s[i+j] == sam[k]){ ok=true; r++; break; } } if(ok){ ok=false; } else{ r--; } } if (r==3 || r==-3) return true; return false; } int main(){ ios::sync_with_stdio(0); cin>>s; int last = -1; LL res = 0; for(unsigned i=0; i<s.size()-2; ++i){ if(check(i)){ res += LL(i-last) * LL(s.size()-i-2); last = i; } } cout<<res<<"\n"; return 0; } |