#include <bits/stdc++.h> using namespace std; typedef long long ll; string s; ll n; ll ans = 0; bool ok(ll i) { int p = i + 3; bool l[3]; for(; i < p; i++) { l[i%3] = false; if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') l[i%3] = true; } if(l[0] == l[1] && l[1] == l[2]) return true; return false; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>s; n = s.size(); ll last = 0; for(ll i = 0; i < n - 2; i++) if(ok(i)) { ans+=(i - last + 1)*(n - i - 2); last = i + 1; } cout<<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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; string s; ll n; ll ans = 0; bool ok(ll i) { int p = i + 3; bool l[3]; for(; i < p; i++) { l[i%3] = false; if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') l[i%3] = true; } if(l[0] == l[1] && l[1] == l[2]) return true; return false; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>s; n = s.size(); ll last = 0; for(ll i = 0; i < n - 2; i++) if(ok(i)) { ans+=(i - last + 1)*(n - i - 2); last = i + 1; } cout<<ans; return 0; } |