728x90
๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/92341?language=javascript
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก, ์ฑ์ฉ๊น์ง Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
ํ๋ก๊ทธ๋๋จธ์ค ๋ ๋ฒจ2 ๋ฌธ์ .
2022 ์นด์นด์ค ๊ธฐ์ถ
์์์๊ฐ ์ฝ 40๋ถ.. ๋ ๋ฒจ 2๋ ์ด์ 30-40๋ถ ์์ ๋๋ผ ์ ์๊ฒ ๋นก๊ณตํด์ผ๊ฒ ๋ค
js์์ map ์๋๋ฉด forEach๋ก ์๋ํด๋ณด๊ธฐ ใ ใ กใ
ํด์๋งต์ ์ฌ์ฉํด์ ํ์ดํ์๋ค.
ํ์ด ์์
1. ๋์ ์๊ฐ ๊ณ์ฐ
2. ์ถ์ฐจ ์ํ๋ฉด 23:59 ์ถ์ฐจ๋ก ๋ณ๊ฒฝ
3. ์๊ฐ -> ๊ธฐ๋ณธ์๊ธ + ์ถ๊ฐ์๊ธ ๊ณ์ฐํ๊ธฐ
๋์ ํ์ด
const timeToMinutes=(timeString)=>{
let time = timeString.split(":");
return Number(time[0])*60 + Number(time[1]);
}
function solution(fees, records) {
var answer = [];
let carTime = new Map();
let carFeeMinutes = new Map();
let carFee = new Map();
records.map((r)=>{
let carNumber = r.substr(6,4);
if(r.substr(11)=='IN'){ // ๋ค์ด์ฌ ๋
carTime.set(carNumber, r.substr(0,5));
}
else{
let inTime = carTime.get(carNumber);
let nowFee = carFeeMinutes.get(carNumber);
let allTime = (timeToMinutes(r.substr(0,5)) - timeToMinutes(inTime));
carFeeMinutes.set(carNumber, nowFee>0 ? nowFee+allTime : allTime)
carTime.set(carNumber, 0);
}
})
carTime.forEach((value, key)=>{
if(value !== 0){
console.log(key);
let allTime = (timeToMinutes("23:59") - timeToMinutes(value));
let nowFee = carFeeMinutes.get(key);
carFeeMinutes.set(key, nowFee>0 ? nowFee+allTime : allTime);
carTime.set(key, 0);
}
})
carFeeMinutes.forEach((value, key)=>{
// fees[0]: ๊ธฐ๋ณธ์๊ฐ, [1]: ๊ธฐ๋ณธ์๊ธ, [2]: ๋จ์์๊ฐ, [3]: ๋จ์์๊ธ
let overtime = value-fees[0];
if(overtime <= 0){
carFee.set(key, fees[1]);
}
else{
let addFee = Math.ceil(overtime/fees[2]);
carFee.set(key, fees[1] + addFee*fees[3]);
}
})
console.log(carFee);
let sortedCarFee = [...carFee].sort((a, b) => a[0].localeCompare(b[0]));
sortedCarFee.forEach((fee)=>{
answer.push(fee[1]);
})
return answer;
}
728x90
๋ฐ์ํ
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Javascript/PGS] Lv.3 : ๋ถ๋๋ณต๊ท (0) | 2025.03.20 |
---|---|
[Javascript/PGS] Lv.3 : ๋ถ๋ ์ฌ์ฉ์(2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด์ญ) (0) | 2025.03.20 |
[MySQL/PGS] Lv.1 : ์ก์ ๋ฌผ๊ณ ๊ธฐ์ ํ๊ท ๊ธธ์ด ๊ตฌํ๊ธฐ (0) | 2025.03.16 |
[MySQL/PGS] Lv.3 : ์ ๊ทธ๋ ์ด๋ ํ ์ ์๋ ์์ดํ ๊ตฌํ๊ธฐ (0) | 2025.03.16 |
[Javascript/PGS] Lv.1 : ๋๋จธ์ง๊ฐ 1์ด ๋๋ ์ ์ฐพ๊ธฐ (0) | 2025.03.16 |