기록하고 까먹지 말기

1764 본문

전공/백준

1764

yha97 2022. 9. 12. 11:21

날짜 : 2022. 09. 12

사용 언어 : python

 

문제

 

 

코드

틀린 코드

import sys

n, m = map(int, sys.stdin.readline().split())
temp = list()
listen = dict()
chk = list()

for i in range(n):
    name = str(sys.stdin.readline().split())
    temp.append(name)
temp.sort()

for i in temp:
    listen[i] = 0

for i in range(m):
    name = str(sys.stdin.readline().split())
    if name in listen:
        chk.append(name)
print(len(chk))
for i in chk:
    print(i[2:len(i)-2])

 

정답코드(chk에서 sort가 되지 않았다)

import sys

temp = list()
listen = dict()
chk = list()
n, m = map(int, sys.stdin.readline().split()) # n, m 입력

for i in range(n): # 들어본 사람의 이름 입력
    name = str(sys.stdin.readline().split())
    temp.append(name)
temp.sort()
for i in temp:
    listen[i] = 0

for i in range(m): # 들어본 적 없는 사람의 이름 입력
    name = str(sys.stdin.readline().split())
    if name in listen: # 들어본 적 있는 사람인 경우
        chk.append(name)
print(len(chk))
chk.sort()
for i in chk:
    print(i[2:len(i)-2])

 

알게된 점

 

 

 

참고 사이트

 

'전공 > 백준' 카테고리의 다른 글

11478  (0) 2022.09.13
1269  (0) 2022.09.13
10816  (0) 2022.09.12
14425  (0) 2022.09.10
10815  (0) 2022.09.09