#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; long long n; vector <int> v; int const c = 200000; v.clear(); cin >> s; n = s.size(); bool tab[c]; for(int i=0; i<n; ++i) { if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') tab[i] = true; else tab[i] = false; } v.push_back(0); for(int i=0; i<n-2; ++i) { if(tab[i] == tab[i+1] && tab[i] == tab[i+2]) v.push_back(i+1); } v.push_back(n-1); long long ans,sum; sum = 0; for(int i=0; i<v.size()-1; ++i) { long long rr; rr = v[i+1] - v[i] + 1; sum+= (rr*(rr-1)) / 2; } ans = (n*(n-1)) / 2 - sum; cout << ans << endl; 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 <iostream> #include <string> #include <vector> using namespace std; int main() { string s; long long n; vector <int> v; int const c = 200000; v.clear(); cin >> s; n = s.size(); bool tab[c]; for(int i=0; i<n; ++i) { if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') tab[i] = true; else tab[i] = false; } v.push_back(0); for(int i=0; i<n-2; ++i) { if(tab[i] == tab[i+1] && tab[i] == tab[i+2]) v.push_back(i+1); } v.push_back(n-1); long long ans,sum; sum = 0; for(int i=0; i<v.size()-1; ++i) { long long rr; rr = v[i+1] - v[i] + 1; sum+= (rr*(rr-1)) / 2; } ans = (n*(n-1)) / 2 - sum; cout << ans << endl; return 0; } |