#include <bits/stdc++.h> long long int n, ost; long long int wynik; std::string s; int tab[200003]; int main() { std::ios_base::sync_with_stdio(false); std::cin>>s; n=s.size(); for(int i=1; i<=n; i++) { tab[i]=tab[i-1]; if(s[i-1]=='a' || s[i-1]=='e' || s[i-1]=='i' || s[i-1]=='o' || s[i-1]=='u' || s[i-1]=='y') tab[i]++; } for(long long int i=3; i<=n; i++) { if((tab[i]-tab[i-3]==0) || (tab[i]-tab[i-3]==3)) { wynik+=(n-i+1)*(i-2-ost); ost=i-2; } } std::cout<<wynik<<"\n"; }
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 | #include <bits/stdc++.h> long long int n, ost; long long int wynik; std::string s; int tab[200003]; int main() { std::ios_base::sync_with_stdio(false); std::cin>>s; n=s.size(); for(int i=1; i<=n; i++) { tab[i]=tab[i-1]; if(s[i-1]=='a' || s[i-1]=='e' || s[i-1]=='i' || s[i-1]=='o' || s[i-1]=='u' || s[i-1]=='y') tab[i]++; } for(long long int i=3; i<=n; i++) { if((tab[i]-tab[i-3]==0) || (tab[i]-tab[i-3]==3)) { wynik+=(n-i+1)*(i-2-ost); ost=i-2; } } std::cout<<wynik<<"\n"; } |