Skip to content

Commit 9a6fe58

Browse files
authored
Merge pull request #1654 from AlgorithmWithGod/LiiNi-coder
[20251212] PGM / LV2 / 주차 요금 계산 / 이인희
2 parents 99cca91 + 1b85533 commit 9a6fe58

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class Solution {
6+
public int[] solution(int[] fees, String[] records) {
7+
Map<String, Integer> totalTime = new TreeMap<>();
8+
Map<String, Integer> inTime = new HashMap<>();
9+
10+
for(String record : records){
11+
String[] parts = record.split(" ");
12+
int hh = Integer.parseInt(parts[0].substring(0, 2));
13+
int mm = Integer.parseInt(parts[0].substring(3, 5));
14+
int time = hh * 60 + mm;
15+
16+
String car = parts[1];
17+
String type = parts[2];
18+
if(type.equals("IN")){
19+
inTime.put(car, time);
20+
} else {
21+
int start = inTime.remove(car);
22+
int duration = time - start;
23+
24+
totalTime.put(car, totalTime.getOrDefault(car, 0) + duration);
25+
}
26+
}
27+
for(String car : inTime.keySet()){
28+
int start = inTime.get(car);
29+
int end = 23 * 60 + 59;
30+
int duration = end - start;
31+
totalTime.put(car, totalTime.getOrDefault(car, 0) + duration);
32+
}
33+
34+
35+
List<Integer> answerList = new ArrayList<>();
36+
int basicTime = fees[0];
37+
int basicFee = fees[1];
38+
int unitTime = fees[2];
39+
int unitFee = fees[3];
40+
41+
for(int time : totalTime.values()){
42+
if(time <= basicTime){
43+
answerList.add(basicFee);
44+
} else {
45+
int extra = time - basicTime;
46+
int count = extra / unitTime;
47+
if(extra%unitTime != 0){
48+
count++;
49+
}
50+
answerList.add(basicFee + count * unitFee);
51+
}
52+
}
53+
int[] answer = new int[answerList.size()];
54+
for(int i = 0; i < answerList.size(); i++){
55+
answer[i] = answerList.get(i);
56+
}
57+
58+
return answer;
59+
}
60+
}
61+
62+
```

0 commit comments

Comments
 (0)