Find words with alternating vowels and consonants: Difference between revisions

C++ code made more readable
(Swift - simplified code)
(C++ code made more readable)
Line 706:
}
return false;
}
 
bool alternating_vowels_and_consonants(const std::string& str) {
for (size_t i = 1, len = str.size(); i < len; ++i) {
if (is_vowel(linestr[i]) == is_vowel(linestr[i - 1])) {
continuereturn false;
}
return true;
}
 
Line 717 ⟶ 725:
std::string line;
for (int n = 1; getline(in, line); ) {
size_t len =if (line.size(); > 9 && alternating_vowels_and_consonants(line))
if (len <= 9)
continue;
bool is_odd_even_word = true;
for (size_t i = 1; i < len; ++i) {
if (is_vowel(line[i]) == is_vowel(line[i - 1])) {
is_odd_even_word = false;
break;
}
}
if (is_odd_even_word)
std::cout << std::setw(2) << n++ << ": " << line << '\n';
}
1,777

edits