Jump to content

Textonyms: Difference between revisions

→‎{{header|C++}}: minor modifications
m (corrected a misspelling in the task's preamble.)
(→‎{{header|C++}}: minor modifications)
Line 396:
 
=={{header|C++}}==
<lang cpp>#include <fstream>
#include <fstream>
#include <iostream>
#include <unordered_map>
Line 434 ⟶ 433:
 
public:
Textonym_Checker(void) : total(0), elements(0), textonyms(0), max_found(0) { }
 
~Textonym_Checker(void) { }
 
void add(const std::string &str) {
std::string mapping;
total += 1+;
 
if (!get_mapping(mapping, str)) return;
Line 446 ⟶ 445:
const int num_strings = values[mapping].size();
 
textonyms +=if (num_strings == 1) ? 1 : 0textonyms++;
elements += 1+;
 
if (num_strings > max_found) {
Line 454 ⟶ 453:
max_found = num_strings;
}
else if (num_strings == max_found) {
max_strings.push_back(mapping);
}
 
values[mapping].push_back(str);
Line 472 ⟶ 470:
std::cout << max_found + 1 << " words each:\n";
 
for (auto it1 =: max_strings.begin(); it1 != max_strings.end(); ++it1) {
std::cout << '\t' << *it1 << " maps to: ";
for (auto it2 =: values[*it1].begin(); it2 != values[*it1].end(); ++it2) {
std::cout << *it2 << " ";
}std::cout << '\n';
std::cout << "\n";
}
std::cout << '\n';
Line 490 ⟶ 487:
else {
std::cout << "Key '" << str << "' matches: ";
for (auto it =: values[str].begin(); it != values[str].end(); ++it)
std::cout << *it << " ";
std::cout << '\n';
}
Line 497 ⟶ 494:
};
 
int main(void)
{
std::stringauto filename = "unixdict.txt";
std::ifstream input(filename);
Textonym_Checker tc;
Line 516 ⟶ 513:
tc.match("27484247");
tc.match("7244967473642");
}</lang>
}
</lang>
{{out}}
<pre>Read 25104 words from unixdict.txt
<pre>
Read 25104 words from unixdict.txt
 
There are 24988 words in unixdict.txt which can be represented by the digit key mapping.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.