#include <iostream> using namespace std; bool sam(char c) { return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'); } int tab[1000002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a; cin >> a; int n=a.size(), last=-1; long long wyn=0; for (int i=0; i<n; i++) { if (sam(a[i])) tab[i]=1; if (i>1 && (tab[i-2]+tab[i-1]+tab[i])%3==0) last=i-2; if (last==-1) continue; wyn+=last+1; } cout << wyn << "\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 | #include <iostream> using namespace std; bool sam(char c) { return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'); } int tab[1000002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a; cin >> a; int n=a.size(), last=-1; long long wyn=0; for (int i=0; i<n; i++) { if (sam(a[i])) tab[i]=1; if (i>1 && (tab[i-2]+tab[i-1]+tab[i])%3==0) last=i-2; if (last==-1) continue; wyn+=last+1; } cout << wyn << "\n"; } |