728x90
https://www.acmicpc.net/problem/1764
1764번: 듣보잡
첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다.
www.acmicpc.net
- 시간
- import 사용 코드 시간이 30배이상 걸렸다...
- 시간이 오래 걸려도 통과는 한다.
- sys.stdin을 쓰도록 습관을 들여야겠다.
- import 사용 코드 시간이 30배이상 걸렸다...
- 코드1 - import
# 듣도 못한 사람 N, 보도 못한 사람 M
N,M = map(int,input().split())
nohear = set(input() for _ in range(N))
nosee = set(input() for _ in range(M))
# nohear과 nosee의 공통 찾기
no = nohear&nosee
# 듣보잡의 수
print(len(no))
# 듣보잡 명단(사전식 정렬)
for n in sorted(no):
print(n)
- 코드2 - sys.stdin
from sys import stdin
# 듣도 못한 사람 N, 보도 못한 사람 M
N,M = stdin.readline().rstrip().split()
nohear = set(stdin.readline().rstrip() for _ in range(int(N)))
nosee = set(stdin.readline().rstrip() for _ in range(int(M)))
# nohear과 nosee의 공통 찾기
no = nohear&nosee
# 듣보잡의 수
print(len(no))
# 듣보잡 명단(사전식 정렬)
for n in sorted(no):
print(n)
728x90
반응형
'TIL - 프로그래밍 > Python 알고리즘' 카테고리의 다른 글
[백준] 7586. 덩치 - Python (0) | 2022.06.12 |
---|---|
[백준] 11723. 집합 - Python (0) | 2022.06.12 |
[백준] 10773. 제로 - Python (0) | 2022.06.10 |
[백준] 2839. 설탕 배달 - Python (0) | 2022.06.09 |
[백준] 2164. 카드2 - Python (0) | 2022.06.09 |
댓글