[๋ฐฑ์ค€-11723] ์ง‘ํ•ฉ / Python

๐Ÿ“š Problem Solving/Baekjoon

 

11723๋ฒˆ: ์ง‘ํ•ฉ

์ฒซ์งธ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์˜ ์ˆ˜ M (1 ≤ M ≤ 3,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์—ฐ์‚ฐ์ด ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

import sys

data = []
for _ in range(int(sys.stdin.readline())):
    command = list(sys.stdin.readline().split())
    if len(command) == 2:
        oper = command[0]
        x = int(command[-1])
    else:
        oper = command[0]

    if oper == "add":
        if x not in data:
            data.append(x)
    elif oper == "remove":
        if x in data:
            data.remove(x)
    elif oper == "check":
        if x not in data:
            print(0)
        else:
            print(1)
    elif oper == "toggle":
        if x not in data:
            data.append(x)
        else:
            data.remove(x)
    elif oper == "all":
        data = [i for i in range(1, 21)]
    elif oper == "empty":
        data = []

 

ํ•ด์„ค

๊ฐ„๋‹จํ•œ ๋ฌธ์ œ!