#include <iostream> #include <string> bool inline isVowel(char& chr) { if (chr == 'a' || chr == 'e' || chr == 'i' || chr == 'o' || chr == 'u' || chr == 'y') return true; return false; } bool inline equalVowel(char* chars) { bool d = isVowel(chars[0]); return d == isVowel(chars[1]) && d == isVowel(chars[2]); } int main() { std::string input; std::cin >> input; int lastStringFound = -1, result = 0, currIndex = 0; if (input.length() < 3) { //what if it is short string... xD std::cout << 0; return 0; } char currChars[3] = { input[0],input[1],input[2] }; //and the rest of cases for (int i = 3; i < input.length(); i++) { if (equalVowel(currChars)) { //checking chars result += (i-3-lastStringFound)* (input.length()-i+1); lastStringFound = i - 3; } currChars[currIndex++] = input[i]; //changing char } //and time for the last case if (equalVowel(currChars)) result += (input.length() - lastStringFound - 3); std::cout << result; 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 | #include <iostream> #include <string> bool inline isVowel(char& chr) { if (chr == 'a' || chr == 'e' || chr == 'i' || chr == 'o' || chr == 'u' || chr == 'y') return true; return false; } bool inline equalVowel(char* chars) { bool d = isVowel(chars[0]); return d == isVowel(chars[1]) && d == isVowel(chars[2]); } int main() { std::string input; std::cin >> input; int lastStringFound = -1, result = 0, currIndex = 0; if (input.length() < 3) { //what if it is short string... xD std::cout << 0; return 0; } char currChars[3] = { input[0],input[1],input[2] }; //and the rest of cases for (int i = 3; i < input.length(); i++) { if (equalVowel(currChars)) { //checking chars result += (i-3-lastStringFound)* (input.length()-i+1); lastStringFound = i - 3; } currChars[currIndex++] = input[i]; //changing char } //and time for the last case if (equalVowel(currChars)) result += (input.length() - lastStringFound - 3); std::cout << result; return 0; } |