11 typedef std::map< std::string, unsigned > freq_type;
13 class print: public std::unary_function< freq_type::value_type, void >
19 print(std::ostream& out, unsigned total, unsigned total_chars)
20 : os(out), total(total), total_chars(total_chars) {}
21 void operator() (const freq_type::value_type& p)
25 os << p.second * (p.first.length()+2) << ": " << p.first << " ("
26 << double(p.second) * (p.first.length()+2) / total_chars * 100
27 << "% / " << double(p.second) / total * 100 << "%)\n";
33 std::setlocale(LC_ALL, "es_AR");
35 unsigned total = 0, total_chars = 0;
37 while (std::cin >> buf) {
40 total_chars += buf.length();
42 for_each(freq.begin(), freq.end(), print(std::cout, total, total_chars));