#include <clocale>
#include <cstdlib>
-typedef std::map< char, unsigned > freq_type;
+typedef std::map< unsigned char, unsigned > freq_type;
class print: public std::unary_function< freq_type::value_type, void >
{
--- /dev/null
+#include <map>
+#include <iostream>
+#include <string>
+#include <iomanip>
+#include <algorithm>
+#include <sstream>
+#include <cctype>
+#include <clocale>
+#include <cstdlib>
+
+typedef std::map< std::string, unsigned > freq_type;
+
+class print: public std::unary_function< freq_type::value_type, void >
+{
+ std::ostream& os;
+public:
+ unsigned total;
+ unsigned total_chars;
+ print(std::ostream& out, unsigned total, unsigned total_chars)
+ : os(out), total(total), total_chars(total_chars) {}
+ void operator() (const freq_type::value_type& p)
+ {
+ os.fill('0');
+ os.width(8);
+ os << p.second * (p.first.length()+2) << ": " << p.first << " ("
+ << double(p.second) * (p.first.length()+2) / total_chars * 100
+ << "% / " << double(p.second) / total * 100 << "%)\n";
+ }
+};
+
+int main(void)
+{
+ std::setlocale(LC_ALL, "es_AR");
+ std::string buf;
+ unsigned total = 0, total_chars = 0;
+ freq_type freq;
+ while (std::cin >> buf) {
+ ++freq[buf];
+ ++total;
+ total_chars += buf.length();
+ }
+ for_each(freq.begin(), freq.end(), print(std::cout, total, total_chars));
+ return 0;
+}
+