백준 2800 - 괄호 제거


백준 2800 - 괄호 제거

123456789101112131415161718192021222324252627from itertools import combinationsimport sys,copy txt = list(sys.stdin.readline().rstrip())n = []idx = [] for i,j in enumerate(txt): if j == '(': txt[i] = "" n += [i] if j == ')': txt[i] = "" idx += [[n.pop(),i]] ans = set()for i in range(len(idx)): for j in combinations(idx,i): tmp = copy.deepcopy(txt) for k,l in j: tmp[k] = "(" tmp[l] = ")" ans.add("".join(tmp)) for i in sorted(ans): print(i)cs enumerate로 문자열의 인덱스 위치를 i, 캐릭터를 j좌측 괄호가 나오면 문자를 지우고 위치를 n에 저장우측 괄호가 나오면 문자를 지우고 인덱스로 괄호 쌍의 위치를..........



원문링크 : 백준 2800 - 괄호 제거