#include <bits/stdc++.h> using namespace std; #ifdef LOCAL template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << "(" << p.first << ", " << p.second << ")"; } template<class C, class = typename C::value_type> typename enable_if<!is_same<C, string>::value, ostream&>::type operator<<(ostream& os, C c) { for (auto i = c.begin(); i != c.end(); i++) { os << " {"[i == c.begin()] << *i << ",}"[next(i) == c.end()]; } return os; } #define debug(x) { cerr << #x << " = " << x << endl; } #else #define debug(...) {} #endif set<char> samogloski({'a', 'e', 'o', 'u', 'y', 'i'}); bool is_samogloska(char x) { return samogloski.find(x) != samogloski.end(); } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; vector<int> tru(s.size()); vector<int> dp(s.size()); long long wynik = 0; for (int i = 0; i < s.size(); i ++) { if (i + 2 < s.size()) { tru[i] = 1; for (int j = 1; j < 3; j ++) { if (is_samogloska(s[i]) != is_samogloska(s[i + j])) tru[i] = 0; } } dp[i] = -1; if (i > 0) dp[i] = dp[i-1]; if (i > 1 && tru[i - 2]) dp[i] = i - 2; wynik += dp[i] + 1; } 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <bits/stdc++.h> using namespace std; #ifdef LOCAL template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << "(" << p.first << ", " << p.second << ")"; } template<class C, class = typename C::value_type> typename enable_if<!is_same<C, string>::value, ostream&>::type operator<<(ostream& os, C c) { for (auto i = c.begin(); i != c.end(); i++) { os << " {"[i == c.begin()] << *i << ",}"[next(i) == c.end()]; } return os; } #define debug(x) { cerr << #x << " = " << x << endl; } #else #define debug(...) {} #endif set<char> samogloski({'a', 'e', 'o', 'u', 'y', 'i'}); bool is_samogloska(char x) { return samogloski.find(x) != samogloski.end(); } int main() { ios_base::sync_with_stdio(false); string s; cin >> s; vector<int> tru(s.size()); vector<int> dp(s.size()); long long wynik = 0; for (int i = 0; i < s.size(); i ++) { if (i + 2 < s.size()) { tru[i] = 1; for (int j = 1; j < 3; j ++) { if (is_samogloska(s[i]) != is_samogloska(s[i + j])) tru[i] = 0; } } dp[i] = -1; if (i > 0) dp[i] = dp[i-1]; if (i > 1 && tru[i - 2]) dp[i] = i - 2; wynik += dp[i] + 1; } cout << wynik <<"\n"; } |