Cod sursa(job #1096417)

Utilizator cordun_cristinaCristina Maria Cordun cordun_cristina Data 1 februarie 2014 23:18:20
Problema Hashuri Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.12 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

int n,op,x,a[1000000],sw,contor,k,i,b,j;
int main()
{
    f>>n;
    for(i=0;i<n;i++)
    {
        sw=0;
        f>>op>>x;
        contor++;
        if(op==1)
        {
            for(j=0;j<contor;j++)
            {
                if(a[j]==x) {sw=1;g<<a[j]<<' ';}
            }
            if(sw==0) a[j+1]=x;
            else contor--;
        }
        if(op==2)
        {
            for(j=0;j<contor;j++)
            {
                if(a[j]==x)
                {
                    for(k=j;k<contor-1;k++)
                    {
                        a[k]=a[k+1];
                    }
                    contor--;
                }
            }
        }
        if(op==3)
        {
            sw=0;
            b=0;
            for(j=0;j<contor;j++)
            {
                if(a[j]==x) b=1;
                else sw=1;
            }
            if(b) g<<b<<'\n';
            else g<<'0'<<'\n';
        }
    }
    f.close();
    g.close();
    return 0;
}