#include <iostream> #include <string> #include <array> using namespace std; const array<char,6> V = {'a','e','i','o','u','y'}; bool check(const string& s) { int r = 0; for(auto c: s) for(auto c2: V) if(c == c2) r += 1; return r == 0 || r == 3; } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; int x = -1, n = s.size(); unsigned long long r = 0; if(s.length() < 3){ cout << 0 << endl; return 0; } for(int i = 0; i + 2 < n; i++) { if(check(s.substr(i,3))) { if(x == -1) r = r + (i + 1) * (n - i - 2); else r = r + (i - x) * (n - i - 2); x = i; } } cout << r << endl; }
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 36 37 38 39 40 41 42 | #include <iostream> #include <string> #include <array> using namespace std; const array<char,6> V = {'a','e','i','o','u','y'}; bool check(const string& s) { int r = 0; for(auto c: s) for(auto c2: V) if(c == c2) r += 1; return r == 0 || r == 3; } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; int x = -1, n = s.size(); unsigned long long r = 0; if(s.length() < 3){ cout << 0 << endl; return 0; } for(int i = 0; i + 2 < n; i++) { if(check(s.substr(i,3))) { if(x == -1) r = r + (i + 1) * (n - i - 2); else r = r + (i - x) * (n - i - 2); x = i; } } cout << r << endl; } |