Word frequency: Difference between revisions

Content added Content deleted
(Modify C++ alternative to ignore case differences, as required by the problem specification.)
m (Modify C++ alternative to use a named constant to specify how many words to list.)
Line 1,510: Line 1,510:
std::map<std::string, int> freq;
std::map<std::string, int> freq;
std::string line;
std::string line;
const int top = 10;


std::ifstream in("135-0.txt");
std::ifstream in("135-0.txt");
Line 1,548: Line 1,549:
"==== ==== =========\n";
"==== ==== =========\n";
int rank = 1;
int rank = 1;
for (auto iter = pairs.cbegin(); iter != pairs.cend() && rank <= 10; ++iter) {
for (auto iter = pairs.cbegin(); iter != pairs.cend() && rank <= top; ++iter) {
std::printf("%2d %4s %5d\n", rank++, iter->first.c_str(), iter->second);
std::printf("%2d %4s %5d\n", rank++, iter->first.c_str(), iter->second);
}
}