// Arkadiusz Roussau // PA2018 - POL[B] #include <iostream> #include <cstdio> #include <utility> #include <string> #include <vector> using namespace std; long long res = 0; bool vowel(char c) { if (c =='a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return true; } return false; } int max(int a, int b) { if (a >= b) { return a; } return b; } int main() { string inputWord; cin >> inputWord; vector<int> nextBadWordPos, prevBadWordPos, isBadWord; isBadWord.resize(inputWord.length() + 1, 0); nextBadWordPos.resize(inputWord.length() + 1, inputWord.length() - 1); prevBadWordPos.resize(inputWord.length() + 1, 0); if (inputWord.length() <= 2) { cout << "0\n"; return 0; } for (int i = 0; i < (inputWord.length() - 2); ++i) { if (vowel(inputWord[i]) && vowel(inputWord[i + 1]) && vowel(inputWord[i + 2])) { isBadWord[i] = 1; } else if (!vowel(inputWord[i]) && !vowel(inputWord[i + 1]) && !vowel(inputWord[i + 2])) { isBadWord[i] = 1; } } int lastBadWordPos = 0; for (int i = 0; i < (inputWord.length() - 2); ++i) { if (isBadWord[i] == 1) { prevBadWordPos[i] = lastBadWordPos; lastBadWordPos = i; } } lastBadWordPos = inputWord.length() - 1; for (int i = (inputWord.length() - 1); i >= 0; --i) { if (isBadWord[i] == 1) { nextBadWordPos[i] = lastBadWordPos; lastBadWordPos = i; } } bool flag = true; for (int i = 0; i < inputWord.length(); ++i) { if (flag && isBadWord[i] == 1) { flag = false; res += 1 + (i - prevBadWordPos[i]) + max(0, ((inputWord.length() - 1) - (i + 2))) + ((i - prevBadWordPos[i]) * max(0, ((inputWord.length() - 1) - (i + 2)))); } else if (isBadWord[i] == 1) { res += 1 + max(0, (i - prevBadWordPos[i] - 1)) + max(0, ((inputWord.length() - 1) - (i + 2))) + (max(0, (i - prevBadWordPos[i] - 1)) * max(0, ((inputWord.length() - 1) - (i + 2)))); } } cout << res << "\n"; 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | // Arkadiusz Roussau // PA2018 - POL[B] #include <iostream> #include <cstdio> #include <utility> #include <string> #include <vector> using namespace std; long long res = 0; bool vowel(char c) { if (c =='a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return true; } return false; } int max(int a, int b) { if (a >= b) { return a; } return b; } int main() { string inputWord; cin >> inputWord; vector<int> nextBadWordPos, prevBadWordPos, isBadWord; isBadWord.resize(inputWord.length() + 1, 0); nextBadWordPos.resize(inputWord.length() + 1, inputWord.length() - 1); prevBadWordPos.resize(inputWord.length() + 1, 0); if (inputWord.length() <= 2) { cout << "0\n"; return 0; } for (int i = 0; i < (inputWord.length() - 2); ++i) { if (vowel(inputWord[i]) && vowel(inputWord[i + 1]) && vowel(inputWord[i + 2])) { isBadWord[i] = 1; } else if (!vowel(inputWord[i]) && !vowel(inputWord[i + 1]) && !vowel(inputWord[i + 2])) { isBadWord[i] = 1; } } int lastBadWordPos = 0; for (int i = 0; i < (inputWord.length() - 2); ++i) { if (isBadWord[i] == 1) { prevBadWordPos[i] = lastBadWordPos; lastBadWordPos = i; } } lastBadWordPos = inputWord.length() - 1; for (int i = (inputWord.length() - 1); i >= 0; --i) { if (isBadWord[i] == 1) { nextBadWordPos[i] = lastBadWordPos; lastBadWordPos = i; } } bool flag = true; for (int i = 0; i < inputWord.length(); ++i) { if (flag && isBadWord[i] == 1) { flag = false; res += 1 + (i - prevBadWordPos[i]) + max(0, ((inputWord.length() - 1) - (i + 2))) + ((i - prevBadWordPos[i]) * max(0, ((inputWord.length() - 1) - (i + 2)))); } else if (isBadWord[i] == 1) { res += 1 + max(0, (i - prevBadWordPos[i] - 1)) + max(0, ((inputWord.length() - 1) - (i + 2))) + (max(0, (i - prevBadWordPos[i] - 1)) * max(0, ((inputWord.length() - 1) - (i + 2)))); } } cout << res << "\n"; return 0; } |