Cod sursa(job #1365580)

Utilizator tidehyonBosoi Bogdan tidehyon Data 28 februarie 2015 13:18:11
Problema Hashuri Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include<iostream>
#include<fstream>
using namespace std;
ofstream g("hashuri.out");
long sir[1000001],op,x,n,r=0,m;
bool FOR(int b)
{
    for(int i=1;i<=r;i++)
        if(sir[i]==b)
        {
            return false;
            m=i;
        }
    return true;
}
void prelucrare(int a,int b)
{
    if(a==1)
    {
       if(FOR(b)==1)
       {
           r++;
           sir[r]=b;
       }
    }
    if(a==2)
    {
        if(FOR(b)==0)
            {
                if(r>1)
                {
                    int aux=sir[r];
                    sir[r]=sir[m];
                    sir[m]=aux;
                    r--;
                }
                if(r==1)
                    r--;
            }
    }
    if(a==3)
    {
        if(FOR(b))
            g << "0" << "\n";
        else g << "1" << "\n";
    }
}
void read()
{
    ifstream f("hashuri.in");
    f >> n;
    for(int i=1;i<=n;i++)
    {
        f >> op >> x;
        prelucrare(op,x);
    }
    f.close();
}
int main()
{
    read();
    g.close();
    return 0;
}