Cod sursa(job #1438639)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 20 mai 2015 15:23:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
// Hashuri
#include <fstream>
#include <vector>
#define Key 10007
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int N;


#define x first
#define y second
template <typename T>
class Hash {
  private:
    std::vector< pair<T, int> > *H;
    int HMAX;
    std::hash<T> myhash;
  public:
    Hash(int hmax = 50007) {
      HMAX = hmax;
      H = new vector< pair<T, int> > [HMAX];
    }

    int& operator[](T key) {
      int i = myhash(key) % HMAX;
      for (typename std::vector< pair<T,int> >::iterator it = H[i].begin(); it != H[i].end(); it++) {
        if (key == it->x) {
          return it->y;
        }
      }
      H[i].push_back( pair<T, int>(key, 0) );
      return H[i].back().y;
    }

    ~Hash() {
      delete[] H;
    }

};

Hash<int> H;

int main()
{
    f>>N;
    for (int i=1;i<=N;++i)
    {
        int tip,x;
        f>>tip>>x;
        if (tip==1)H[x] = 1;;
        if (tip==2)H[x] = 0;
        if (tip==3)g << H[x] <<'\n';
    }
    f.close();g.close();
    return 0;
}