๋ฐ์ํ
import Foundation
let NM = readLine()!.components(separatedBy: " ").map { Int($0)! }
let N = NM[0]
let M = NM[1]
var pokedex1 = [String: Int]()
var pokedex2 = [Int: String]()
for i in 0..<N{
let pokmon = readLine()!
pokedex1[pokmon] = i+1
pokedex2[i+1] = pokmon
}
// ๋ฌธ์ ๊ฐ ์ํ๋ฒณ์ผ๋ก๋ง ๋ค์ด์ค๋ฉด ํฌ์ผ๋ชฌ ๋ฒํธ๋ฅผ ๋งํด์ผ ํ๊ณ
// ์ซ์๋ก๋ง ๋ค์ด์ค๋ฉด ํฌ์ผ๋ชฌ ๋ฒํธ์ ํด๋นํ๋ ๋ฌธ์๋ฅผ ์ถ๋ ฅํด์ผํจ
for _ in 0..<M{
let q = readLine()!
if let index = Int(q) {
print(pokedex2[index]!)
} else {
print(pokedex1[q]!)
}
}
์๊ฐ์ด๊ณผ๊ฐ ๋์์ ๋์ ๋๋ฆฌ 2๊ฐ ๋ง๋ค์ด์ ํ์๋ค.
๋ฐ์ํ
'๐ ์ฝํ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค 1927 ์ต์ ํ (0) | 2023.04.11 |
---|---|
[Swift] ๋ฐฑ์ค 1074 Z (0) | 2023.04.11 |
[Swift] ๋ฐฑ์ค2630 ์์ข ์ด ๋ง๋ค๊ธฐ (0) | 2023.04.04 |
[Swift] ๋ฐฑ์ค 1541 ์์ด๋ฒ๋ฆฐ ๊ดํธ (0) | 2023.04.04 |
[Swift] ๋ฐฑ์ค 1922 ์ฟผ๋ํธ๋ฆฌ (0) | 2023.04.04 |