File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ # Dict 풀이 시간:
2+ # 시간(ms) : 720
3+ # 공간(KB) : 266652
4+ #
5+ # Counter 풀이 시간:
6+ # 시간(ms) : 672
7+ # 공간(KB) : 266708
8+ #
9+ # 공유 :
10+ # - Counter는 collections 모듈에 포함된 dict의 특수 버전. 내부는 사실상 dict 기반이지만, 추가 메서드와 연산자 지원
11+
12+
13+ import sys
14+ from collections import Counter
15+ input = sys .stdin .readline
16+
17+
18+ # 1. dictionary 사용
19+ input ()
20+ nums = list (input ().strip ().split ()) # 숫자 카드 입력 받기
21+
22+ dic = {}
23+ for n in nums : # dictionary로 입력 받은 숫자 카드 개수 카운드
24+ dic [n ] = dic .get (n , 0 ) + 1
25+
26+ input ()
27+ ans = []
28+ for m in list (input ().strip ().split ()) : # dic에서 숫자 카드 개수 가져오기
29+ ans .append (dic .get (m , 0 ))
30+ print (* ans )
31+
32+
33+
34+ # 2. Counter 사용
35+ input ()
36+ nums = list (input ().strip ().split ()) # 숫자 카드 입력 받기
37+ counter = Counter (nums )
38+
39+ input ()
40+ ans = []
41+ for m in list (input ().strip ().split ()) : # dic에서 숫자 카드 개수 가져오기
42+ ans .append (counter [m ])
43+ print (* ans )
44+
You can’t perform that action at this time.
0 commit comments