Cod sursa(job #3129420)

Utilizator Maria_VerdesVerdes Maria-Ioana Maria_Verdes Data 14 mai 2023 14:09:03
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.53 kb
#include <fstream>
#include <vector>

using namespace std;

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

int main()
{
    const int p = 9973; //cel mai mare numar prim de care am dat
    vector <vector <int>> liste;
    int q;
    f >> q;
    for(int i = 1; i <= q; i++)
    {
        int optiune, x;
        f >> optiune >> x;
        int val = x % p;
        while(liste.size() <= val)
            liste.push_back({}); //trebuie sa alocam spatiu pt liste
        switch(optiune)
        {
        case 1:
            {
                bool gasit = false;
                for(int j = 0; j < liste[val].size() && !gasit; j++)
                    if(liste[val][j] == x)
                        gasit = true;
                if(!gasit) liste[val].push_back(x);
                break;
            }
        case 2:
            {
                for(int j = 0; j < liste[val].size(); j++)
                    if(liste[val][j] == x)
                    {
                        liste[val].erase(liste[val].begin() + j);
                        break;
                    }
                break;
            }
        case 3:
            {
                bool gasit = false;
                for(int j = 0; j < liste[val].size() && !gasit; j++)
                    if(liste[val][j] == x)
                        gasit = true;
                if(gasit) g << 1 << endl;
                else g << 0 << endl;
                break;
            }
        }
    }
    f.close();
    g.close();
    return 0;
}