일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- TS
- webpack
- useAppDispatch
- 반공변성
- app router
- Promise
- tailwind
- 태그된 유니온
- Cypress
- 인터섹션
- 이분 검색
- SSR
- async/await
- 투포인터
- 무한 스크롤
- 공변성
- autosize
- recoil
- CI/CD
- React
- dfs
- 리터럴 타입
- 타입 좁히기
- 결정 알고리즘
- 호이스팅
- Jest
- map
- CORS
- ESlint
- RTK Query
Archives
- Today
- Total
짧은코딩
10816 숫자 카드 2 본문
반응형
https://www.acmicpc.net/problem/10816
내 풀이(맞음)
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
if a[i] in dic:
dic[a[i]] += 1
else:
dic[a[i]] = 1
m = int(input())
b = list(map(int, input().split()))
rst = []
for i in range(m):
if b[i] in dic:
rst.append(dic[b[i]])
else:
rst.append(0)
for i in rst:
print(i, end = ' ')
처음에 그냥 푸니까 시간 제한이 걸렸다. 그래서 딕셔너리 자료형을 사용했다. 그래서 a[i]가 dic 안에 있으면 value 값에 1을 더한다. 만약에 없으면 key와 value를 1로 해서 추가한다. 그리고 m, b를 입력받고 b[i]가 dic 안에 있으면 rst에 b[i]의 value 값을 더하고 없으면 0을 추가한다.
반응형
'코딩 테스트(Python) > 백준, 프로그래머스' 카테고리의 다른 글
1764 듣보잡 (0) | 2022.02.23 |
---|---|
1966 프린터 큐 (0) | 2022.02.23 |
1158 요세푸스 문제 (0) | 2022.02.19 |
11279 최대 힙 (0) | 2022.02.14 |
4949 균형잡힌 세상 (0) | 2022.02.12 |
Comments