#include <iostream> #include <string> using namespace std; typedef long long ll; #define sz(x) ((int)x.size()) const string samo = "aeiouy"; const int MAXCHAR = 255; ll answer; bool is_samo[MAXCHAR]; int main() { for(auto &c : samo) is_samo[c] = true; ios_base::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); string k; cin >> k; int last_correct = 0; for(int i = 0; i < sz(k) - 2; ++i) { // cout << "sprawdzam " << k[i] << endl; if((is_samo[k[i]] == is_samo[k[i + 1]]) && (is_samo[k[i]] == is_samo[k[i + 2]]) && (is_samo[k[i + 1]] == is_samo[k[i + 2]])) { // cout << "zgadza sie[" << i << "] = " << k[i] << " " << k[i + 1] << " " << k[i + 2] << endl; answer += (max(1, i - last_correct + 1) * max(1, sz(k) - (i + 3) + 1)); last_correct = i + 1; } } cout << answer << 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 | #include <iostream> #include <string> using namespace std; typedef long long ll; #define sz(x) ((int)x.size()) const string samo = "aeiouy"; const int MAXCHAR = 255; ll answer; bool is_samo[MAXCHAR]; int main() { for(auto &c : samo) is_samo[c] = true; ios_base::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); string k; cin >> k; int last_correct = 0; for(int i = 0; i < sz(k) - 2; ++i) { // cout << "sprawdzam " << k[i] << endl; if((is_samo[k[i]] == is_samo[k[i + 1]]) && (is_samo[k[i]] == is_samo[k[i + 2]]) && (is_samo[k[i + 1]] == is_samo[k[i + 2]])) { // cout << "zgadza sie[" << i << "] = " << k[i] << " " << k[i + 1] << " " << k[i + 2] << endl; answer += (max(1, i - last_correct + 1) * max(1, sz(k) - (i + 3) + 1)); last_correct = i + 1; } } cout << answer << endl; return 0; } |