본문 바로가기
Algorithm/etc

[파이썬] 백준 - 14단계 집합과 맵

by 베짱이28호 2023. 4. 18.

[파이썬] 백준 - 14단계 집합과 맵


숫자카드 (10815)

N = int(input())
card = set(map(int,input().split()))
M = int(input())
compare = list(map(int,input().split()))
for i in compare:
    if i in card:
        print(1,end=' ')
    else:
        print(0,end=' ')

문자열 집합 (11425)

N,M = map(int,input().split())
count = 0
table = {}
for i in range(N):
    S = input()
    table[S] = 0

for i in range(M):
    check = input()
    if check in table :
        table[check] += 1
        
temp = list(table.values())
print(sum(temp))

회사에 있는 사람 (7785)

N = int(input())
table = {}
for i in range(N):
    name,now = map(str,input().split())
    table[name] = now
result = [key for key, value in table.items() if value == 'enter']
result.sort(reverse=True)
for i in result:
    print(i)

나는야 포켓몬 마스터 이다솜 (1620)

import sys
N,M = map(int,input().split())
num_name,name_num = {},{}
for i in range(N):
    a = sys.stdin.readline().strip()
    num_name[i+1] = a
    name_num[a] = i+1
for i in range(M):
    a = sys.stdin.readline().strip()
    if  'A' <= a[0] <= 'z' :
        print(name_num[a])
    else : 
        print(num_name[int(a)])

sys 쓸줄 몰라서 5번은 틀렸다.. 코드는 잘 짰는데


숫자카드2 (10816)

N = int(input())
card_list = list(map(int,input().split()))
card_set = set(card_list)
M = int(input())
compare = list(map(int,input().split()))

table = dict(zip(card_set,[0 for i in range(len(card_set))]))

for i in card_list :
    if i in table:
        table[i] += 1
        
for j in compare :
    if j in table:
        print(table[j],end=' ')
    else :
        print(0,end=' ')

듣보잡 (1764)

N,M = map(int,input().split())
name,answer = {},[]

for i in range(N):
    a = input()
    name[a] = 0
    
for i in range(M):
    b = input() 
    if b in name : 
        answer.append(b)
answer.sort()

print(len(answer))
for i in answer : 
    print(i)

대칭차집합 (1269)

A,B = map(int,input().split())
set_A = set(map(int,input().split()))
set_B = set(map(int,input().split()))
AB = list(set_A^set_B)
print(len(AB))

서로 다른 부분 문자열의 개수 (11478)

S = input()
word = set(S)
count = len(word)+1 
for i in range(2,len(S)):
    temp = {}
    for j in range(len(S)-i+1):
        if S[j:j+i] not in temp :
            temp[S[j:j+i]] = 0
            count += 1
print(count)

댓글