#include #include #include #include using namespace std; int size = 20000; int * C; // this counts the number of strings that share each possible hash value const int max_occurs = 20; int occurs[max_occurs]; // this counts the number of times each linked list length occurs int hash(string s) { unsigned int value = 79561; for (int i = 0; i < s.length(); i += 1) value = value * 69 + s[i]; return value % size; } int main(int argc, char * argv[]) { if (argc == 2) size = atoi(argv[1]); C = new int[size]; for (int i = 0; i < size; i += 1) C[i] = 0; for (int i = 0; i < max_occurs; i += 1) occurs[i] = 0; while (true) { string s; cin >> s; if (cin.fail()) break; int pos = hash(s); C[pos] += 1; } for (int i = 0; i < size; i += 1) if (C[i] < max_occurs) occurs[C[i]] += 1; for (int i = 0; i < max_occurs; i += 1) { int spcs = 200 * occurs[i] / size; cout << setw(2) << i << ": " << setw(5) << occurs[i] << " |" << setw(spcs) << "" << "*\n"; } }