#include <iostream> #include <cstring> char vovels[] = { 'a', 'e', 'i', 'o', 'u', 'y' }; bool isVovel(char ch) { for (int i = 0; i < 6; i++) { if (ch == vovels[i]) { return true; } } return false; } int main() { long numberOfDifficultWords = 0; long numberOf3LetterDifficultWords = 0; char chArr[200000]; std::cin.getline(chArr, 200000); int prevLeft = 0; bool isDifficultWord = false; for (int i = 0; i < strlen(chArr); i++) { if (i <= strlen(chArr) - 3) { if (isVovel(chArr[i]) && isVovel(chArr[i+1]) && isVovel(chArr[i+2])) { isDifficultWord = true; } if (!isDifficultWord && !isVovel(chArr[i]) && !isVovel(chArr[i + 1]) && !isVovel(chArr[i + 2])) { isDifficultWord = true; } if (isDifficultWord) { //to the right numberOfDifficultWords = numberOfDifficultWords + 1 + i + strlen(chArr) - 3 - i - i; //to the left numberOfDifficultWords = numberOfDifficultWords + i - numberOf3LetterDifficultWords - prevLeft; //to the left and right numberOfDifficultWords = numberOfDifficultWords + ((i - numberOf3LetterDifficultWords- prevLeft)*(i + strlen(chArr) - 3 - i - i )); prevLeft = i -numberOf3LetterDifficultWords; numberOf3LetterDifficultWords++; } } isDifficultWord = false; } printf("%d", numberOfDifficultWords); 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 | #include <iostream> #include <cstring> char vovels[] = { 'a', 'e', 'i', 'o', 'u', 'y' }; bool isVovel(char ch) { for (int i = 0; i < 6; i++) { if (ch == vovels[i]) { return true; } } return false; } int main() { long numberOfDifficultWords = 0; long numberOf3LetterDifficultWords = 0; char chArr[200000]; std::cin.getline(chArr, 200000); int prevLeft = 0; bool isDifficultWord = false; for (int i = 0; i < strlen(chArr); i++) { if (i <= strlen(chArr) - 3) { if (isVovel(chArr[i]) && isVovel(chArr[i+1]) && isVovel(chArr[i+2])) { isDifficultWord = true; } if (!isDifficultWord && !isVovel(chArr[i]) && !isVovel(chArr[i + 1]) && !isVovel(chArr[i + 2])) { isDifficultWord = true; } if (isDifficultWord) { //to the right numberOfDifficultWords = numberOfDifficultWords + 1 + i + strlen(chArr) - 3 - i - i; //to the left numberOfDifficultWords = numberOfDifficultWords + i - numberOf3LetterDifficultWords - prevLeft; //to the left and right numberOfDifficultWords = numberOfDifficultWords + ((i - numberOf3LetterDifficultWords- prevLeft)*(i + strlen(chArr) - 3 - i - i )); prevLeft = i -numberOf3LetterDifficultWords; numberOf3LetterDifficultWords++; } } isDifficultWord = false; } printf("%d", numberOfDifficultWords); return 0; } |