hiho Week 15 register

Ended

Participants:1653

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-13 13:22:44

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
#define MAX 100001
class 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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX