๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution/Programmers

[Swift] 2018 KAKAO BLIND RECRUITMENT [1์ฐจ] ์…”ํ‹€๋ฒ„์Šค

by Fomagran ๐Ÿ’ป 2021. 8. 6.
728x90
๋ฐ˜์‘ํ˜•

Problem

 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - [1์ฐจ] ์…”ํ‹€๋ฒ„์Šค

10 60 45 ["23:59","23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59"] "18:00"

programmers.co.kr


Solution

 

1.timetable์„ ์ ์€ ์‹œ๊ฐ„ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

 

   var times:[Int] = timetable.map{Int($0.split(separator: ":")[0])!*60 + Int($0.split(separator: ":")[1])!}.sorted(by:<)

 

2. ๊ฐ ์‹œ๊ฐ„๋งˆ๋‹ค ํƒˆ  ์ˆ˜ ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์„ timetable์—์„œ ์‚ญ์ œํ•ด์ค€๋‹ค.

 

for _ in 0..<n {
        people = m
        for _ in 0..<m {
            if times.isEmpty || times.first! > time { break }
            last = times.removeFirst()
            people -= 1
        }
        time += t
    }

 

3. ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ๋ฒ„์Šค์—  ํƒˆ ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

 

๋งŒ์•ฝ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ๋ฒ„์Šค์— ํƒˆ ์ž๋ฆฌ๊ฐ€ ๋‚จ์•˜๋‹ค๋ฉด ๋งˆ์ง€๋ง‰ ๋ฒ„์Šค๊ฐ€ ์˜จ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ํ•˜๊ณ 

 

์ž๋ฆฌ๊ฐ€ ์—†๋‹ค๋ฉด ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— ํƒ„ ์‚ฌ๋žŒ๋ณด๋‹ค 1๋ถ„ ๋น ๋ฅธ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค.

 

    time = people == 0 ? last-1 : time-t
    hour = time/60  < 10 ? "0\(time/60)" : "\(time/60)"
    minute = time%60 < 10 ? "0\(time%60)" : "\(time%60)"
    return hour + ":" + minute

Source Code

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€