// // Created by cw386224 on 10.12.18. // #include <string> #include <iostream> bool isVowel(char c) { static const std::string vowels = "aeiouy"; return vowels.find(c) != std::string::npos; } bool isHard(const std::string &greetings, size_t posLast) { if (posLast < 2) return false; return (isVowel(greetings[posLast]) == isVowel(greetings[posLast - 1]) && isVowel(greetings[posLast]) == isVowel(greetings[posLast - 2])); } int main() { std::string greetings; std::cin>>greetings; bool foundHardSegment = false; size_t lastHardSegmentBegin = 0; size_t hardGreetingsCount = 0; for (size_t i = 0; i < greetings.size(); i++) { if (isHard(greetings, i)) { lastHardSegmentBegin = i - 2; foundHardSegment = true; } if (foundHardSegment) { hardGreetingsCount += lastHardSegmentBegin + 1; } } std::cout<<hardGreetingsCount; }
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 | // // Created by cw386224 on 10.12.18. // #include <string> #include <iostream> bool isVowel(char c) { static const std::string vowels = "aeiouy"; return vowels.find(c) != std::string::npos; } bool isHard(const std::string &greetings, size_t posLast) { if (posLast < 2) return false; return (isVowel(greetings[posLast]) == isVowel(greetings[posLast - 1]) && isVowel(greetings[posLast]) == isVowel(greetings[posLast - 2])); } int main() { std::string greetings; std::cin>>greetings; bool foundHardSegment = false; size_t lastHardSegmentBegin = 0; size_t hardGreetingsCount = 0; for (size_t i = 0; i < greetings.size(); i++) { if (isHard(greetings, i)) { lastHardSegmentBegin = i - 2; foundHardSegment = true; } if (foundHardSegment) { hardGreetingsCount += lastHardSegmentBegin + 1; } } std::cout<<hardGreetingsCount; } |