SHARE
TWEET

Untitled

a guest Nov 16th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. ifstream fin("set.in");
  8. ofstream fout("set.out");
  9. vector <int> HashTable(1000001);
  10.  
  11. int GetHash(int element)
  12. {
  13.     int Hash = abs((int)(element % 1000001));
  14.     return Hash;
  15. }
  16. void Insert(int element)
  17. {
  18.     int Hash = GetHash(element);
  19.     if (HashTable[Hash] == NULL)
  20.         HashTable[Hash] = element;
  21. }
  22. void Exists(int element)
  23. {
  24.     int Hash = GetHash(element);
  25.     if (HashTable[Hash] != NULL)
  26.         fout << "true\n";
  27.     else
  28.         fout << "false\n";
  29. }
  30. void Delete(int element)
  31. {
  32.     int Hash = GetHash(element);
  33.     HashTable[Hash] = NULL;
  34. }
  35. int main() {
  36.     string s;
  37.     int element;
  38.     while (fin >> s)
  39.     {
  40.         switch (s[0])
  41.         {
  42.         case 'i':
  43.         {
  44.             fin >> element;
  45.             Insert(element);
  46.             break;
  47.         }
  48.         case 'e':
  49.         {
  50.             fin >> element;
  51.             Exists(element);
  52.             break;
  53.         }
  54.         case 'd':
  55.         {
  56.             fin >> element;
  57.             Delete(element);
  58.             break;
  59.         }
  60.         }
  61.     }
  62.     return 0;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top