Cod sursa(job #496041)

Utilizator cristiprgPrigoana Cristian cristiprg Data 27 octombrie 2010 17:13:07
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <cstdio>
#define DIM 1000005
int N = 0, v[DIM];

void afis()
{
    for(int i = 1; i <= N; ++i)
        printf("%d ", v[i]);
    printf("\n----------------------\n");
}

void add(int x)
{
    v[++N] = x;
}

void del(int x)
{
    for (int i = 1; i <= N; ++i)
        if (v[i] == x)
        {
            for (;i<N;++i)
                v[i] = v[i+1];
            --N;
            return ;
        }
}

int search(int x)
{
    for (int i = 1; i <= N; ++i)
        if (v[i] == x)
            return 1;

    return 0;
}

int main()
{
    int n,type, x;
    FILE *f = fopen("hashuri.in", "r"), *out = fopen("hashuri.out", "w");
    fscanf(f, "%d", &n);
    for (;n;--n)
    {
        fscanf(f, "%d", &type);
        fscanf(f, "%d", &x);
        if (type == 1)
            add(x);

        else
            if (type == 2)
                del(x);
            else
                fprintf(out, "%d\n", search(x));

    }

    fclose(f);
    fclose(out);

    return 0;
}