Cod sursa(job #3130872)

Utilizator opreaopreacalin@gmail.comCalin Oprea [email protected] Data 18 mai 2023 18:53:34
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.22 kb
#include <fstream>
using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

struct lista
{
    long element;
    lista *next;
};
lista lis[100001];

int main()
{
    long long n,x,ind,i,op;
    in>>n;

    lista *list1,*list2;

    for(i=1;i<=n;i++)
    {
        in>>op>>x;
        ind= x % 100000 - 1;
        list1= lis + ind;
        if (op==1)
        {while (list1->next && list1->element != x)
                list1=list1->next;
            if (list1->element != x)
            {
                list2=new lista;
                list2->element=x;
                list2->next=NULL;
                list1->next=list2;
            }
        }
        else
        if(op==2)
        {
            while(list1->next && list1->next->element != x)
                list1=list1->next;
            if (list1->next)
            { list2=list1->next;
                list1->next=list1->next->next;
                delete list2;
            }
        }
        else
        if (op==3)
        {
            while(list1->next && list1->element != x)
                list1=list1->next;
            if (list1->element == x) out << 1 << endl;
            else out<<0<<"\n";
        }
    }
    in.close();
    out.close();
    return 0;
}