#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <string> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cstdio> #include <algorithm> #include <stack> #include <iomanip> #include <limits> #include <cctype> using namespace std; bool T[26]; bool isSequenceHard(char c1, char c2, char c3) { int i1 = c1 - 97, i2 = c2 - 97, i3 = c3 - 97; if(T[c1 - 97] && T[c2 - 97] && T[c3 - 97]) { return true; } if(!T[c1 - 97] && !T[c2 - 97] && !T[c3 - 97]) { return true; } return false; } int main(int argc, char const *argv[]) { std::ios::sync_with_stdio(false); for(int i = 0; i < 26; ++i) { T[i] = false; } T['a' - 97] = true; T['e' - 97] = true; T['i' - 97] = true; T['o' - 97] = true; T['u' - 97] = true; T['y' - 97] = true; string s; cin >> s; int pos = -1; long long res = 0; for(int i = 2; i < s.size(); ++i) { if(isSequenceHard(s[i - 2], s[i - 1], s[i])) { pos = i - 2; } res += pos + 1; } cout << res << 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <iostream> #include <vector> #include <queue> #include <algorithm> #include <string> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cstdio> #include <algorithm> #include <stack> #include <iomanip> #include <limits> #include <cctype> using namespace std; bool T[26]; bool isSequenceHard(char c1, char c2, char c3) { int i1 = c1 - 97, i2 = c2 - 97, i3 = c3 - 97; if(T[c1 - 97] && T[c2 - 97] && T[c3 - 97]) { return true; } if(!T[c1 - 97] && !T[c2 - 97] && !T[c3 - 97]) { return true; } return false; } int main(int argc, char const *argv[]) { std::ios::sync_with_stdio(false); for(int i = 0; i < 26; ++i) { T[i] = false; } T['a' - 97] = true; T['e' - 97] = true; T['i' - 97] = true; T['o' - 97] = true; T['u' - 97] = true; T['y' - 97] = true; string s; cin >> s; int pos = -1; long long res = 0; for(int i = 2; i < s.size(); ++i) { if(isSequenceHard(s[i - 2], s[i - 1], s[i])) { pos = i - 2; } res += pos + 1; } cout << res << endl; return 0; } |