Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <string>#include <cstdio>#include <vector>using namespace std;#define MAX 100001class HashTable{private:static const int SIZE = 1009;vector<pair<string, int> > table[SIZE];int ord;public:HashTable() : ord(0) {}int& operator[] (const char *in){int slot = 0;string str;while (*in){slot = (31 * slot + *in) % SIZE;str.push_back(*in);++in;}for (int i = 0; i < table[slot].size(); ++i){if (table[slot][i].first == str)return table[slot][i].second;}table[slot].push_back(make_pair(str, ord++));return table[slot].back().second;