Cod sursa(job #581801)

Utilizator drywaterLazar Vlad drywater Data 14 aprilie 2011 16:39:15
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.53 kb
#include <stdio.h>
const int mod=666013;
int i,n,x,t,res,ok;
struct nod{int x; nod *next;};
nod *G[mod];
int main(void)
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%d",&t,&x);
        res=x%mod;
        if (t==1)
        {
           ok=0;
           nod *it=new nod;
           it=G[res];
           while (it)
           {
               if (it->x==x) {ok=1; break;}
               it=it->next;
           }
           if (!ok)
           {
               it=new nod;
               it->x=x;
               it->next=G[res];
               G[res]=it;
           }
        }
        if (t==2)
        {
           ok=0;
           nod *it=new nod;
           it=G[res];
           if (it && it->x==x) ok=1;
           while (it && it->next)
           {
               if (it->next->x==x) {ok=1; break;}
               it=it->next;
           }
           if (ok)
           {
               if (!G[res]->next) G[res]=NULL;
               else
                {
                    nod *nou=it->next;
                    it->next=it->next->next;
                    delete it;

                }
           }
        }
        if (t==3)
        {
           ok=0;
           nod *it=new nod;
           it=G[res];
           while (it)
           {
               if (it->x==x) {ok=1; break;}
               it=it->next;
           }
           printf("%d\n",ok);
        }
    }
    return 0;
}