#include <iostream> #include <string> //SMG - samogloska, SPG - spolgloska using namespace std; bool isSMG(char& c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int numStreak = 0; bool smgStreak = true; int lastStreakBegin = -1; int res = 0; for (int i = 0; i < s.size(); i++) { if (smgStreak == isSMG(s[i])) { numStreak++; }else { smgStreak = !smgStreak; numStreak = 1; } if (numStreak >= 3) { lastStreakBegin = i - 2; } res += lastStreakBegin + 1; } cout << res; }
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> //SMG - samogloska, SPG - spolgloska using namespace std; bool isSMG(char& c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int numStreak = 0; bool smgStreak = true; int lastStreakBegin = -1; int res = 0; for (int i = 0; i < s.size(); i++) { if (smgStreak == isSMG(s[i])) { numStreak++; }else { smgStreak = !smgStreak; numStreak = 1; } if (numStreak >= 3) { lastStreakBegin = i - 2; } res += lastStreakBegin + 1; } cout << res; } |