Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <set>
- #include <math.h>
- #include <list>
- using namespace std;
- typedef long long int lli;
- class Set {
- private:
- const lli PRIME_SIZE = 1000001;
- vector<list<lli>>* hashTable;
- int hash(lli num) const {
- return abs(num % PRIME_SIZE);
- }
- public:
- Set() {
- this->hashTable = new vector<list<lli>>(PRIME_SIZE);
- }
- void insert(lli num) {
- lli index = hash(num);
- for (auto i : hashTable->at(index))
- if (i == num)
- return;
- hashTable->at(index).push_back(num);
- }
- void erase(lli num) {
- lli index = hash(num);
- for (auto iter = hashTable->at(index).begin(); iter != hashTable->at(index).end(); iter++) {
- if (*iter == num) {
- hashTable->at(index).erase(iter);
- return;
- }
- }
- }
- bool find(lli num) const {
- lli index = hash(num);
- for (auto iter = hashTable->at(index).begin(); iter != hashTable->at(index).end(); iter++)
- if (*iter == num)
- return true;
- return false;
- }
- };
- int main() {
- ifstream ist("set.in");
- ofstream ost("set.out");
- Set newSet;
- string com;
- lli num;
- while (ist >> com >> num) {
- if (com == "insert")
- newSet.insert(num);
- else if (com == "delete")
- newSet.erase(num);
- else
- ost << (newSet.find(num) ? "true" : "false") << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement