• Home
  • About
    • JOOS photo

      JOOS

      Joos's blog

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[백준] 11723번 : 집합 with python3

23 Aug 2018

Reading time ~1 minute

https://www.acmicpc.net/problem/11723

import sys
r = lambda: sys.stdin.readline().strip()

m = int(input())
ans = 0

while m :
    m -= 1
    st = r()
    state = st.split()
    list_len = len(state)
    cmd = state[0]

    if list_len == 2:
        num = int(state[1])
        num -=1
        if cmd == 'add':
            ans = ans | (1 << num)
        elif cmd == 'remove':
            ans = ans & ~(1 << num)
        elif cmd == 'check':
            ck = ans & (1 << num)
            if ck > 0 :
                print(1)
            else:
                print(0)
        elif cmd == 'toggle':
            ans = ans ^ (1 << num)
    else:
        if cmd == 'all':
            ans = (1 << 20)-1
        elif cmd == 'empty':
            ans =  0

0으로 shift를 해도 한칸 옮겨지기 때문에 0부터 시작한다고 볼 수 있다. 그럼으로 num을 받고 -1을 해야 원하는 결과가 나온다.



algorithm백준 Share Tweet +1