#include <iostream> using namespace std; inline bool isVowel(char c) { if (c == 'e' || c == 'y' || c == 'u' || c == 'i' || c == 'o' || c == 'a') { return true; } else { return false; } } inline bool isGroup(int vowels, int consonants) { if (vowels >= 3 || consonants >= 3) { return true; } else { return false; } } int main() { int vAcc = 0, cAcc = 0, gAcc = 0; long long sum = 0; bool groupMet = false; string greeting; cin >> greeting; int greetingSize = greeting.size(); for (int i = 0; i < greetingSize; i++) { if (isVowel(greeting[i])) { vAcc++; cAcc = 0; } else { cAcc++; vAcc = 0; } if (isGroup(vAcc, cAcc)) { int fwdAcc = greetingSize - 1 - i; if (!groupMet) { gAcc = gAcc - 2; if (gAcc < 0) { gAcc = 0; } } sum++; sum += gAcc; sum += fwdAcc; sum += (gAcc * fwdAcc); gAcc = 0; groupMet = true; } else { gAcc++; } } cout << sum; 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 59 60 61 62 63 | #include <iostream> using namespace std; inline bool isVowel(char c) { if (c == 'e' || c == 'y' || c == 'u' || c == 'i' || c == 'o' || c == 'a') { return true; } else { return false; } } inline bool isGroup(int vowels, int consonants) { if (vowels >= 3 || consonants >= 3) { return true; } else { return false; } } int main() { int vAcc = 0, cAcc = 0, gAcc = 0; long long sum = 0; bool groupMet = false; string greeting; cin >> greeting; int greetingSize = greeting.size(); for (int i = 0; i < greetingSize; i++) { if (isVowel(greeting[i])) { vAcc++; cAcc = 0; } else { cAcc++; vAcc = 0; } if (isGroup(vAcc, cAcc)) { int fwdAcc = greetingSize - 1 - i; if (!groupMet) { gAcc = gAcc - 2; if (gAcc < 0) { gAcc = 0; } } sum++; sum += gAcc; sum += fwdAcc; sum += (gAcc * fwdAcc); gAcc = 0; groupMet = true; } else { gAcc++; } } cout << sum; return 0; } |