-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces_RegistrationSystem.cpp
More file actions
74 lines (61 loc) · 1.34 KB
/
Codeforces_RegistrationSystem.cpp
File metadata and controls
74 lines (61 loc) · 1.34 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 10000;
class HashTable
{
private:
static const int MAXSIZE = 10000;
list<pair<string, long long>> table[MAXSIZE];
public:
unsigned long long hashFunction(string key);
unsigned long long getTablesize(unsigned long long hashIndex, string name);
void insertItem(string name);
void printTable();
};
unsigned long long HashTable::hashFunction(string key)
{
unsigned long long rslt{};
for (unsigned long long i = 0; i < key.length(); i++)
{
rslt += key[i];
}
return rslt % SIZE;
}
void HashTable::insertItem(string name)
{
unsigned long long hashValue = hashFunction(name);
auto &cell = table[hashValue];
auto bItr = begin(cell);
bool keyExists = false;
for (; bItr != end(cell); bItr++)
{
if (bItr->first == name)
{
keyExists = true;
long long posi = bItr->second;
posi++;
bItr->second = posi;
cout << name << posi << endl;
break;
}
}
if (!keyExists)
{
cout << "OK\n";
cell.emplace_back(name, 0);
}
return;
}
int main()
{
HashTable HT;
unsigned long long n;
cin >> n;
while (n--)
{
string name;
cin >> name;
HT.insertItem(name);
}
return 0;
}