-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset.cpp
More file actions
65 lines (59 loc) · 1.34 KB
/
set.cpp
File metadata and controls
65 lines (59 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
vector<list<int>> all;
static const int size_ = 1e4 + 121;
int hash_(int &x) {
return abs(x % size_);
}
string exist_(int &x) {
int i = hash_(x);
bool have = false;
if (!all[i].empty()) {
for (auto it = all[i].begin(); it != all[i].end(); it++) {
if (*it == x) {
have = true;
break;
}
}
}
return ((have) ? ("true") : ("false"));
}
void delete_(int &x) {
int i = hash_(x);
if (!all[i].empty()) {
for (auto it = all[i].begin(); it != all[i].end(); it++) {
if (*it == x) {
all[i].erase(it);
break;
}
}
}
}
int main() {
freopen("set.in", "r", stdin);
freopen("set.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
all.resize(size_);
while (cin >> s) {
int x;
cin >> x;
if (s[0] == 'i') {
if (exist_(x) == "false") {
int i = hash_(x);
all[i].push_back(x);
}
}
else if (s[0] == 'e') {
cout << exist_(x) << '\n';
}
else if (s[0] == 'd') {
delete_(x);
}
}
}