#include <iostream> using namespace std; bool samogloska(char c) { bool ret = false; if (c == 'a' || c == 'e' || c== 'i' || c == 'o' || c == 'u' || c== 'y' ) { ret = true; } return ret; } long long count(string s) { int samogloski = 0; long long ret = 0, prev_start = -1, start = -1; for (int i = 0; i < s.size(); i++) { if (!samogloska(s[i])) { if (samogloski >= 0) { samogloski = -1; start = i; } else { samogloski--; if (samogloski < -3) start++; } } else { if (samogloski > 0) { samogloski++; if (samogloski > 3) start++; } else { samogloski = 1; start = i; } } if (samogloski > 2 || samogloski < -2) { ret = ret + (start - prev_start) * (s.size() - i); prev_start = start; } } return ret; } int main() { string s; cin >> s; cout << count(s) << 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 43 44 45 46 | #include <iostream> using namespace std; bool samogloska(char c) { bool ret = false; if (c == 'a' || c == 'e' || c== 'i' || c == 'o' || c == 'u' || c== 'y' ) { ret = true; } return ret; } long long count(string s) { int samogloski = 0; long long ret = 0, prev_start = -1, start = -1; for (int i = 0; i < s.size(); i++) { if (!samogloska(s[i])) { if (samogloski >= 0) { samogloski = -1; start = i; } else { samogloski--; if (samogloski < -3) start++; } } else { if (samogloski > 0) { samogloski++; if (samogloski > 3) start++; } else { samogloski = 1; start = i; } } if (samogloski > 2 || samogloski < -2) { ret = ret + (start - prev_start) * (s.size() - i); prev_start = start; } } return ret; } int main() { string s; cin >> s; cout << count(s) << endl; } |