Development Project

[ Baekjoon - 단계별로 풀어보기(06/06~06/08) ] - 12단계 : 집합과 맵 본문

CodingTest/Baekjoon

[ Baekjoon - 단계별로 풀어보기(06/06~06/08) ] - 12단계 : 집합과 맵

나를 위한 시간 2022. 6. 6. 13:07
  • 10815 : 숫자 카드
import sys
n = int(sys.stdin.readline().strip())
getNum = set(map(int,sys.stdin.readline().split()))
m = int(sys.stdin.readline().strip())
checkNum = list(map(int,sys.stdin.readline().split()))
for i in checkNum:
    if i in getNum:
        print(1)
    else:
        print(0)
#
import sys

N = int(sys.stdin.readline().rstrip('\n'))
numbers = set(map(int, sys.stdin.readline().rstrip('\n').split()))
M = int(sys.stdin.readline().rstrip('\n'))

def map_cards(i):
    if i in numbers:
        return "1"
    else:
        return "0"
    
print(" ".join (map(map_cards, map(int, sys.stdin.readline().rstrip('\n').split()))))

 

  • 14425 : 문자열 집합
import sys
input = sys.stdin.readline

a,b=map(int,input().split())
al=[input() for _ in range(a)]
cnt=0
for _ in range(b):
    t = input()
    if t in al:
        cnt += 1
print(cnt)

 

  • 1620 : 나는야 포켓몬 마스터
n,m=map(int,input().split())
ans=[input() for _ in range(n)]
qes=[input() for _ in range(m)]

dic={}
for i,name in enumerate(ans):
  dic[i+1]=name
rev_dic={v:k for k,v in dic.items()}

for i in range(m):
  inp=qes[i]
  print(rev_dic[inp] if not inp.isnumeric() else dic[int(inp)])

 

  • 10816 : 숫자 카드 2
from bisect import bisect_left, bisect_right
from sys import stdin

n = stdin.readline().rstrip()
card = list(map(int,stdin.readline().split()))
m = stdin.readline().rstrip()
test = list(map(int,stdin.readline().split()))
card.sort()

def count_by_range(a, left_value, right_value):
    right_index = bisect_right(a, right_value)
    left_index = bisect_left(a, left_value)
    return right_index - left_index


for i in range(len(test)):
    print(count_by_range(card, test[i], test[i]), end=' ')

 

  • 1764 : 듣보잡
a,b=map(int,input().split())
a=set([input() for _ in range(a)])
b=set([input() for _ in range(b)])

l=sorted(list(a&b))
print(len(l))
for i in l:
    print(i)

 

  • 1269 : 대칭 차집합
a,b=map(int,input().split())
A=set(map(int,input().split()))
B=set(map(int,input().split()))
print(len((A-B)|(B-A)))

 

  • 11478 : 서로 다른 부분 문자열의 개수
s=input()
res=set()

for i in range(len(s)):
  for j in range(i,len(s)):
    temp=s[i:j+1]
    res.add(temp)
print(len(res))
Comments