fork download
  1. import java.io.*;
  2. import java.util.HashSet;
  3. import java.util.Set;
  4. import java.util.StringTokenizer;
  5.  
  6. /**
  7.  
  8. https://w...content-available-to-author-only...c.net/problem/11723
  9. 집합
  10. */
  11. public class Main {
  12.  
  13. public static void main(String[] args) throws IOException {
  14. int commandSize = Integer.parseInt(br.readLine());
  15. Set<Integer> S = new HashSet<>();
  16. Set<Integer> allS = new HashSet<>();
  17. Set<Integer> emptyS = new HashSet<>();
  18.  
  19. for(int i = 0; i < 20; i++) {
  20. allS.add(i + 1);
  21. }
  22.  
  23. for(int i = 0; i < commandSize; i++) {
  24. String read = br.readLine();
  25. String command = st.nextToken();
  26.  
  27. if(command.equals("add")) {
  28. S.add(Integer.parseInt(st.nextToken()));
  29.  
  30. } else if(command.equals("check")) {
  31. if(S.contains(Integer.parseInt(st.nextToken()))) {
  32. bw.write(1 + "\n");
  33. }else {
  34. bw.write(0 + "\n");
  35. }
  36.  
  37. } else if(command.equals("toggle")) {
  38. int x = Integer.parseInt(st.nextToken());
  39. if(S.contains(x)) {
  40. S.remove(x);
  41. } else {
  42. S.add(x);
  43. }
  44. } else if(command.equals("remove")) {
  45. S.remove(Integer.parseInt(st.nextToken()));
  46.  
  47. } else if(command.equals("all")) {
  48. S = allS;
  49.  
  50. } else if(command.equals("empty")) {
  51. S = emptyS;
  52.  
  53. }
  54. }
  55.  
  56. br.close();
  57. bw.flush();
  58. bw.close();
  59. }
  60. }
Success #stdin #stdout 0.09s 55000KB
stdin
4
empty
add 1
empty
check 1
stdout
1