Cod sursa(job #2905088)

Utilizator pasare.franci@yahoo.comPasare Francisca [email protected] Data 19 mai 2022 15:47:47
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>
#include <vector>
 
using namespace std;
 
ifstream in("hashuri.in");
ofstream out("hashuri.out");
 
const int MOD = 1234567;
vector <int> G[MOD + 2];
int N;
int p, nr;
 
int Find(int Value)
{
  int List = Value % MOD;
  for(int i = 0; i < (int)G[List].size(); ++i)
    if(G[List][i] == Value)
      return i;
  return -1;
}
 
void Insert(int Value)
{
  int List = Value % MOD;
  if(Find(Value) == -1)
    G[List].push_back(Value);
 
}
 
void Delete(int Value)
{
  int List = Value % MOD,Pos = Find(Value);
  if(Pos != -1)
    G[List].erase(G[List].begin() + Pos);
}
 
int main()
{
    in >> N;
    for(int i = 1; i <= N; ++i){
      in >> p >> nr;
      if(p == 1)
        Insert(nr);
      else if(p == 2)
        Delete(nr);
      else
          out << (Find(nr) != -1) << "\n";
    }
    return 0;
}