Skip to content

Commit 13d060e

Browse files
committed
[Feat] 주차 요금 계산
1 parent 42d6972 commit 13d060e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Diff for: src/3week/jaewon/주차 요금 계산.kt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class jaewon_Solution {
2+
fun solution(fees: IntArray, records: Array<String>): IntArray {
3+
var answer: IntArray = intArrayOf()
4+
val keys = records.groupBy{it.split(" ")[1]}
5+
val blank = keys.keys.associateWith{0}.toMutableMap()
6+
7+
keys.values.forEach{ key ->
8+
val times = key.map{(it.split(" ")[0].split(":"))}.flatten().toMutableList()
9+
if(times.size%4 != 0){
10+
times.add("23")
11+
times.add("59")
12+
}
13+
var i = 0
14+
var total = 0
15+
repeat(times.size/4){
16+
// 입출차 셋트
17+
var h = (times[i+2].toInt()-times[i].toInt()) * 60
18+
var m = times[i+3].toInt()-times[i+1].toInt()
19+
total += h+m
20+
i+=4
21+
}
22+
blank[key[0].split(" ")[1]] = total
23+
}
24+
25+
answer = blank.mapValues{
26+
val v = it.value
27+
var temp = 0
28+
if(fees[0] < v){
29+
val add = if((v-fees[0])%fees[2] != 0) (v-fees[0])/fees[2]+1 else (v-fees[0])/fees[2]
30+
temp = add*fees[3]
31+
}
32+
fees[1] + temp
33+
}.toList().sortedBy{it.first}.map{it.second}.toIntArray()
34+
return answer
35+
}
36+
}
37+
38+
fun main(){
39+
jaewon_Solution().solution(
40+
intArrayOf(180,5000,10,600), arrayOf("05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT")
41+
)
42+
}

0 commit comments

Comments
 (0)