Cod sursa(job #2885904)

Utilizator Cosmina_GheorgheGheorghe Cosmina Cosmina_Gheorghe Data 6 aprilie 2022 19:19:41
Problema Hashuri Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> hashh[15];
int main()
{
    int j,nr,i,ok,clasa,k=10,x,y;
    f>>nr;
    for(j=0;j<nr;j++)
    {
        f>>x;
        f>>y;
        ok=0;
        clasa=y%k;
        for(int i=0;i<hashh[clasa].size();i++)
        {
            if( hashh[clasa][i]==y)
            {
                ok=1;
                break;
            }
        }
        if (x==1)
        {
            if(!ok)
            {
                hashh[clasa].push_back(y);
            }
        }

        if(x==2)
        {
            if(ok)
            {
                swap(hashh[clasa][i], hashh[clasa].back());
                hashh[clasa].pop_back();
            }
        }
        if(x==3)
        {
            g<<ok<<endl;
        }
    }
    g.close();
    f.close();
}