Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 이분탐색
- 자바
- db
- 투포인터
- 건강
- DP
- 문제해결
- 시뮬레이션
- priorityqueue
- 프로그래머스
- SQL
- math
- MySQL
- 운동기록
- 알고리즘
- 코딩테스트
- 코테
- 문자열
- greedy
- dfs
- binary search
- COS PRO
- 문제풀이
- 백준
- BOJ
- 러닝일지
- Java
- BFS
- SWEA
- oracle
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 주차 요금 계산 본문





[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/92341#qna
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
public int[] solution(int[] fees, String[] records) {
Map<Integer,Integer> inTime = new HashMap<>();
Map<Integer,Integer> outTime = new HashMap<>();
for(String order : records){
String[] info = order.split(" ");
String[] time = info[0].split(":");
int timeInfo = Integer.valueOf(time[0])*60 + Integer.valueOf(time[1]);
int car = Integer.valueOf(info[1]);
if(info[2].equals("IN")){
inTime.put(car,timeInfo);
}
else{
int totalTime = timeInfo - inTime.get(car);
outTime.put(car,outTime.getOrDefault(car,0) + totalTime);
inTime.remove(car);
}
}
for(int car : inTime.keySet()){
int totalTime = 23*60+59 - inTime.get(car);
outTime.put(car,outTime.getOrDefault(car,0)+totalTime);
}
List<Integer> list = new ArrayList<>(outTime.keySet());
Collections.sort(list);
int[] answer = new int[list.size()];
for(int i=0;i<list.size();i++){
int time = outTime.get(list.get(i));
int totalFee = 0;
totalFee = fees[1];
if(time>fees[0]) {
time -= fees[0];
totalFee += (int)Math.ceil((double)time / fees[2])*fees[3];
}
answer[i] = totalFee;
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.2 오픈채팅방 (0) | 2025.10.17 |
|---|---|
| [프로그래머스] Lv.2 2 x n 타일 (0) | 2025.10.17 |
| [프로그래머스] Lv.2 숫자 변환하기 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 스킬트리 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 택배상자 (0) | 2025.10.16 |