반응형
문제
https://www.acmicpc.net/problem/17219
풀이
Dictionary에 대한 이해만 있다면 쉽게 풀 수 있는 문제
[String: String] 형태의 빈 Dictionary 프로퍼티를 생성하고, n개의 입력만큼 key value로 할당해준다.
그 이후, dictionary에 value를 출력해주면 되는 문제
이 문제에서는 '반드시 이미 저장된 사이트 주소가 입력된다.' 라는 문장이 있기 때문에 강제 언래핑을 해줘도 무방하다.
소스코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let input = readLine()!.split { $0 == " " }.map { Int($0)! } | |
let n = input[0], m = input[1] | |
var dict: [String: String] = [:] | |
for _ in 0..<n { | |
let input = readLine()!.split { $0 == " " }.map { String($0) } | |
let key = input[0], value = input[1] | |
dict[key] = value | |
} | |
var answer = "" | |
for _ in 0..<m { answer += "\(dict[readLine()!]!)\n" } | |
print(answer) |
후기
난이도가 실버 4로 책정이 되었는데, Dictionary만 알고 있다면 브론즈 수준의 문제
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 9095 1, 2, 3 더하기 (Swift) (0) | 2025.01.12 |
---|---|
[BOJ] 백준 1003 피보나치 함수 (Swift) (0) | 2025.01.12 |
[BOJ] 백준 1240 노드사이의 거리 (Swift) (0) | 2024.11.03 |
[BOJ] 백준 2346 풍선 터뜨리기(Swift) (1) | 2024.11.02 |
[BOJ] 백준 14502 연구소(Swift) (1) | 2024.11.02 |