#include #include #include #include #include #include #include #include using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef unsigned int ui; typedef unsigned char byte; unsigned int mystery(string s) { int h = 47281232; for (int i = 0; i < s.length(); i += 1) h = (h + s[i]) * 14983; return h; } const int tabsize = 100000; int main(int argc, char * argv[]) { if (argc != 2) { cerr << "usage: " << argv[0] << " \n"; exit(1); } string words[tabsize]; int counts[tabsize]; bzero(counts, sizeof(counts)); ifstream fi(argv[1]); while (true) { string s; fi >> s; if (fi.fail()) break; unsigned p = mystery(s) % tabsize; words[p] = s; counts[p] += 1; } while (true) { string s; cout << "> "; cin >> s; unsigned p = mystery(s) % tabsize; cout << s << " appeared " << counts[p] << "times\n"; } }