๋ฌธ์ ์ค๋ช
๋ฌธ์ ํ์ด
๋จ์ํ ๊ตฌํ๋ฌธ์ ๋ค. ํต์ฌ์ 1๋ฌ์ 29์ผ์ด๋ผ๋ ์ ๊ฐ๋ค.
๋ ์ง๋ฅผ ์ ์๋ก ๋ณํํด์ฃผ๋ ํจ์๋ฅผ ๋ง๋ค์ด์ ํด๊ฒฐํ๋ค.
ex) 2021.10.21 ์ผ ๋
(2021 * 29 * 12) + (10 * 29) + (21)
์ฝ๋
func solution(_ today:String, _ terms:[String], _ privacies:[String]) -> [Int] {
// ๋
๋๋ฅผ ์ ์๋ก ๋ฐ๊ฟ์ฃผ๋ ํจ์ ex) 2021.02.05 -> 2021*29*12 + 2*29 + 5
func dateToInt(_ date: String) -> Int {
let split = date.split(separator: ".").map {Int(String($0))!}
return (split[0]*12*29)+(split[1]*29)+split[2]
}
var dict: [String: Int] = [:]
let today = dateToInt(today)
var answer: [Int] = []
// ex) A: 5, B: 3
for term in terms {
let split = term.split(separator: " ").map {String($0)}
dict[split[0]] = Int(split[1])!
}
for i in 0..<privacies.count {
let split = privacies[i].split(separator: " ").map {String($0)}
let date = dateToInt(split[0]) + dict[split[1]]!*29
// ์ ํจ๊ธฐ๊ฐ ์ง๋ฌ์ผ๋ฉด
if today >= date {
answer.append(i+1)
}
}
return answer
}
ํ๊ธฐ
ํ์ด์๊ฐ : 15๋ถ
์ด์ ์ ์๊ฐ์ Intํ์ผ๋ก ๋ณํํ๋ ๊ธฐ์ต์ ์ด๋ ค ๊ฐ๋จํ๊ฒ ํ์๋ค. ๊ตฟ
'์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค 92341] ์ฃผ์ฐจ ์๊ธ ๊ณ์ฐ swift (1) | 2023.11.03 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค 92335] k์ง์์์ ์์ ๊ฐ์ ๊ตฌํ๊ธฐ swift (0) | 2023.10.30 |
[ํ๋ก๊ทธ๋๋จธ์ค 150369] ํ๋ฐฐ ๋ฐฐ๋ฌ๊ณผ ์๊ฑฐํ๊ธฐ swift (0) | 2023.10.28 |
[ํ๋ก๊ทธ๋๋จธ์ค 150368] ์ด๋ชจํฐ์ฝ ํ ์ธํ์ฌ swift (1) | 2023.10.25 |
[ํ๋ก๊ทธ๋๋จธ์ค 86971] ์ ๋ ฅ๋ง์ ๋๋ก ๋๋๊ธฐ swift (2) | 2023.10.13 |