일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- nestjs
- pipex
- 데이터중심애플리케이션설계
- django #ninja #django-ninja #장고
- 네스트JS
- docker
- data-root
- ecole42
- dockerd
- Daemon
- 42
- Born2beroot #42
- Spring
- 42Seoul
- Spring-Boot
Archives
- Today
- Total
혼자 정리
17219번: 비밀번호 찾기 본문
C++
#include <iostream>
#include <map>
using namespace std;
int N, M;
map<string, string> m1;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++){
string tmp1, tmp2;
cin >> tmp1 >> tmp2;
m1.insert(pair<string, string>(tmp1, tmp2));
}
for (int i = 0; i < M; i++){
string tmp;
cin >> tmp;
cout << m1.find(tmp)->second << "\n";
}
}
Python
import sys
diction = {}
N, M = map(int, input().split())
for _ in range(N):
tmp = sys.stdin.readline().split()
diction[tmp[0]] = tmp[1]
for _ in range(M):
print(diction[input()])
- cpp는 맵, 파이썬은 딕셔너리 사용
- 맵은 $O ( max ( N \cdot log(N) , M \cdot log(M) ))$
- 딕셔너리는 해시이므로 $O ( max( N, M))$
'알고리즘 문풀 > 백준' 카테고리의 다른 글
11659번: 구간 합 구하기 4 (0) | 2021.08.08 |
---|---|
9375번: 패션왕 신해빈 (0) | 2021.08.08 |
14891번: 톱니바퀴 (0) | 2021.08.06 |
14890번: 경사로 (0) | 2021.08.06 |
3190번: 뱀 (0) | 2021.08.05 |