#include #include using namespace std; const int tablesize = 100000; string table[tablesize]; int hash(string m) { int h = 3562134; for (int i = 0; i < m.length(); i += 1) h = h * 691 + m[i]; if (h < 0) h = -h; return h % tablesize; } int main() { int unique = 0, collision = 0; while (true) { string s; cin >> s; if (cin.fail()) break; int h = hash(s); if (table[h] == "") { // cout << "new word '" << s << "'\n"; unique += 1; table[h] = s; } else if (table[h] != s) { collision += 1; cout << "collision between '" << s << "' and '" << table[h] << "'\n"; } else { // cout << "word '" << s << "' already present in table\n"; } } cout << unique << " unique words\n"; cout << collision << " collisions\n"; }