Find words which contains all the vowels: Difference between revisions

m
imported>AldoBaldo
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 443:
stupefaction
sulfonamide</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <bitset>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
 
bool contains_all_vowels_once(const std::string& word) {
std::bitset<5> vowels;
for (char ch : word) {
ch = std::tolower(static_cast<unsigned char>(ch));
size_t bit = 0;
switch (ch) {
case 'a': bit = 0; break;
case 'e': bit = 1; break;
case 'i': bit = 2; break;
case 'o': bit = 3; break;
case 'u': bit = 4; break;
default: continue;
}
if (vowels.test(bit))
return false;
vowels.set(bit);
}
return vowels.all();
}
 
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 word;
int n = 0;
while (getline(in, word)) {
if (word.size() > 10 && contains_all_vowels_once(word))
std::cout << std::setw(2) << ++n << ": " << word << '\n';
}
return EXIT_SUCCESS;
}</syntaxhighlight>
 
{{out}}
<pre>
1: ambidextrous
2: bimolecular
3: cauliflower
4: communicable
5: communicate
6: consanguine
7: consultative
8: countervail
9: exclusionary
10: grandiloquent
11: importunate
12: incommutable
13: incomputable
14: insupportable
15: loudspeaking
16: malnourished
17: mensuration
18: oneupmanship
19: pandemonium
20: permutation
21: perturbation
22: portraiture
23: praseodymium
24: stupefaction
25: sulfonamide
</pre>
 
=={{header|C}}==
Line 678 ⟶ 605:
 
Press Return to exit...
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <bitset>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
 
bool contains_all_vowels_once(const std::string& word) {
std::bitset<5> vowels;
for (char ch : word) {
ch = std::tolower(static_cast<unsigned char>(ch));
size_t bit = 0;
switch (ch) {
case 'a': bit = 0; break;
case 'e': bit = 1; break;
case 'i': bit = 2; break;
case 'o': bit = 3; break;
case 'u': bit = 4; break;
default: continue;
}
if (vowels.test(bit))
return false;
vowels.set(bit);
}
return vowels.all();
}
 
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 word;
int n = 0;
while (getline(in, word)) {
if (word.size() > 10 && contains_all_vowels_once(word))
std::cout << std::setw(2) << ++n << ": " << word << '\n';
}
return EXIT_SUCCESS;
}</syntaxhighlight>
 
{{out}}
<pre>
1: ambidextrous
2: bimolecular
3: cauliflower
4: communicable
5: communicate
6: consanguine
7: consultative
8: countervail
9: exclusionary
10: grandiloquent
11: importunate
12: incommutable
13: incomputable
14: insupportable
15: loudspeaking
16: malnourished
17: mensuration
18: oneupmanship
19: pandemonium
20: permutation
21: perturbation
22: portraiture
23: praseodymium
24: stupefaction
25: sulfonamide
</pre>
 
Line 2,302:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./fmt" for Fmt
 
var wordList = "unixdict.txt" // local copy
9,477

edits