#include <cstdio> #include <vector> bool isVowel(const char letter) { return letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'y'; } int main() { char letter = getchar(); bool isLastVowel = isVowel(letter); int noChangeCnt = 1; int cnt = 1; std::vector<int> difficultSequencePositions; letter = getchar(); while (letter >= 'a' && letter <= 'z') { if (isLastVowel == isVowel(letter)) { if (noChangeCnt == 2) { difficultSequencePositions.push_back(cnt - 2); } else { noChangeCnt++; } } else { isLastVowel = !isLastVowel; noChangeCnt = 1; } cnt++; letter = getchar(); } int prev = -1; long long int result = 0; for (auto it = difficultSequencePositions.begin(); it != difficultSequencePositions.end(); ++it) { result += (long long int)(*it - prev) * (cnt - (*it + 2)); prev = *it; } printf("%lld", 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 | #include <cstdio> #include <vector> bool isVowel(const char letter) { return letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'y'; } int main() { char letter = getchar(); bool isLastVowel = isVowel(letter); int noChangeCnt = 1; int cnt = 1; std::vector<int> difficultSequencePositions; letter = getchar(); while (letter >= 'a' && letter <= 'z') { if (isLastVowel == isVowel(letter)) { if (noChangeCnt == 2) { difficultSequencePositions.push_back(cnt - 2); } else { noChangeCnt++; } } else { isLastVowel = !isLastVowel; noChangeCnt = 1; } cnt++; letter = getchar(); } int prev = -1; long long int result = 0; for (auto it = difficultSequencePositions.begin(); it != difficultSequencePositions.end(); ++it) { result += (long long int)(*it - prev) * (cnt - (*it + 2)); prev = *it; } printf("%lld", result); return 0; } |