[백준/파이썬] 18119번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 18119번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
백준 18119번 문제를 풀이합니다.
코드
`python import sys; read = sys.stdin.readline
def strToBit(word): result = 0 for ch in word: result |= 1 « (ord(ch) - ord(‘a’))
return result
n, m = map(int, read().split())
words = [strToBit(read()[:-1]) for _ in range(n)] memory = strToBit(map(lambda i: chr(ord(‘a’)+i), range(26))) result = []
for i in range(m): query, ch = input().split() query = int(query)
if query == 2: memory |= strToBit(ch)
else: memory &= ~strToBit(ch)
cnt = 0
for word in words:
if word & memory == word: cnt += 1
result.append(str(cnt))
print(‘\n’.join(result)) ```
설명
저장소의 기존 제출 코드를 기준으로 정리한 풀이입니다.
댓글남기기