Cod sursa(job #2026647)

Utilizator gabib97Gabriel Boroghina gabib97 Data 24 septembrie 2017 19:54:39
Problema Hashuri Scor 100
Compilator java Status done
Runda Arhiva educationala Marime 1.29 kb
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scan cin = new Scan("hashuri.in");
        PrintWriter cout = new PrintWriter("hashuri.out");
        HashMap<Integer, Integer> H = new HashMap<Integer, Integer>();

        int t, x, n = cin.nextInt();
        while (n-- != 0) {
            t = cin.nextInt();
            x = cin.nextInt();

            if (t == 1) {
                if (!H.containsKey(x))
                    H.put(x, 1);
            } else if (t == 2)
                H.remove(x);
            else {
                if (H.containsKey(x)) cout.print("1\n");
                else cout.print("0\n");
            }
        }

        cout.close();
    }

    static class Scan {
        static BufferedReader br;
        static StringTokenizer st;

        Scan(String file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreElements())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}