Find words with alternating vowels and consonants: Difference between revisions
Content deleted Content added
Added Swift solution |
Added C++ solution |
||
Line 171: | Line 171: | ||
} |
} |
||
fclose(fp); |
fclose(fp); |
||
return EXIT_SUCCESS; |
|||
}</lang> |
|||
{{out}} |
|||
<pre style="height:30em"> |
|||
1: aboriginal |
|||
2: apologetic |
|||
3: bimolecular |
|||
4: borosilicate |
|||
5: calorimeter |
|||
6: capacitate |
|||
7: capacitive |
|||
8: capitoline |
|||
9: capitulate |
|||
10: caricature |
|||
11: colatitude |
|||
12: coloratura |
|||
13: colorimeter |
|||
14: debilitate |
|||
15: decelerate |
|||
16: decolonize |
|||
17: definitive |
|||
18: degenerate |
|||
19: deliberate |
|||
20: demodulate |
|||
21: denominate |
|||
22: denotative |
|||
23: deregulate |
|||
24: desiderata |
|||
25: desideratum |
|||
26: dilapidate |
|||
27: diminutive |
|||
28: epigenetic |
|||
29: facilitate |
|||
30: hemosiderin |
|||
31: heretofore |
|||
32: hexadecimal |
|||
33: homogenate |
|||
34: inoperative |
|||
35: judicature |
|||
36: latitudinal |
|||
37: legitimate |
|||
38: lepidolite |
|||
39: literature |
|||
40: locomotive |
|||
41: manipulate |
|||
42: metabolite |
|||
43: nicotinamide |
|||
44: oratorical |
|||
45: paragonite |
|||
46: pejorative |
|||
47: peridotite |
|||
48: peripatetic |
|||
49: polarimeter |
|||
50: recitative |
|||
51: recuperate |
|||
52: rehabilitate |
|||
53: rejuvenate |
|||
54: remunerate |
|||
55: repetitive |
|||
56: reticulate |
|||
57: savonarola |
|||
58: similitude |
|||
59: solicitude |
|||
60: tananarive |
|||
61: telekinesis |
|||
62: teratogenic |
|||
63: topologize |
|||
64: unilateral |
|||
65: unimodular |
|||
66: uninominal |
|||
67: verisimilitude |
|||
</pre> |
|||
=={{header|C++}}== |
|||
<lang cpp>#include <cstdlib> |
|||
#include <fstream> |
|||
#include <iomanip> |
|||
#include <iostream> |
|||
#include <string> |
|||
bool is_vowel(char ch) { |
|||
switch (ch) { |
|||
case 'a': case 'A': |
|||
case 'e': case 'E': |
|||
case 'i': case 'I': |
|||
case 'o': case 'O': |
|||
case 'u': case 'U': |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
int main(int argc, char** argv) { |
|||
const char* filename = argc < 2 ? "unixdict.txt" : argv[1]; |
|||
std::ifstream in(filename); |
|||
if (!in) { |
|||
std::cerr << "Cannot open file '" << filename << "'.\n"; |
|||
return EXIT_FAILURE; |
|||
} |
|||
std::string line; |
|||
for (int n = 1; getline(in, line); ) { |
|||
size_t len = line.size(); |
|||
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'; |
|||
} |
|||
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
||
}</lang> |
}</lang> |