Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include <list>
  4. #include<string>
  5.  
  6. int const m = 1000001;
  7. using namespace std;
  8.  
  9. int hash_func(int k)
  10. {
  11.     return abs(k % 1000001);
  12. }
  13.  
  14.  
  15. int main() {
  16.  
  17.     list<int>* array= new list<int>[m];
  18.     string operation;
  19.     int temp;
  20.     string ifEx = "false";
  21.     ifstream fin;
  22.     fin.open("set.in");
  23.     ofstream fout;
  24.     fout.open("set.out");
  25.     while (!fin.eof()) {
  26.         operation = "";
  27.         fin >> operation;
  28.         if (operation == "insert") {
  29.             fin >> temp;
  30.             array[hash_func(temp)].push_back(temp);
  31.         }
  32.         if (operation == "delete") {
  33.             fin >> temp;
  34.                     array[hash_func(temp)].remove(temp);
  35.            
  36.         }
  37.         if (operation == "exists") {
  38.             fin >> temp;
  39.             for(auto i= array[hash_func(temp)].begin(); i!= array[hash_func(temp)].end();i++){
  40.                 if (*i == temp) {
  41.                     ifEx = "true";
  42.                     break;
  43.                 }
  44.             }
  45.             fout << ifEx << "\n";
  46.             ifEx = "false";
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement