#include<bits/stdc++.h> using namespace std; long long dp[200010][5]; bool sam(char x) { if((x=='a')||(x=='e')||(x=='i')||(x=='o')||(x=='u')||(x=='y')) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,i; string s; cin>>s; n=s.size(); for(i=2;i<n;i++) { dp[i][0]=dp[i-1][2]; if((sam(s[i])==sam(s[i-1]))&&(sam(s[i])==sam(s[i-2]))) dp[i][1]=i-1; else dp[i][1]=dp[i-1][1]; dp[i][2]=dp[i][0]+dp[i][1]; } cout<<dp[n-1][2]; 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 | #include<bits/stdc++.h> using namespace std; long long dp[200010][5]; bool sam(char x) { if((x=='a')||(x=='e')||(x=='i')||(x=='o')||(x=='u')||(x=='y')) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,i; string s; cin>>s; n=s.size(); for(i=2;i<n;i++) { dp[i][0]=dp[i-1][2]; if((sam(s[i])==sam(s[i-1]))&&(sam(s[i])==sam(s[i-2]))) dp[i][1]=i-1; else dp[i][1]=dp[i-1][1]; dp[i][2]=dp[i][0]+dp[i][1]; } cout<<dp[n-1][2]; return 0; } |