(1).백준 25286번 11월 11일은 이름과는 다르게 이전달 월말의 년월일을 출력해야 하는 문제였다.
2월을 제외한 달은 고정값을 가지고 있기 때문에
해당 값의 이전달의 일 수를 기록한 map을 사용했으며
2월의 경우 주어진 조건에 따라 일 수를 변경해서 출력했다.
const input = `6
2000 3
2012 3
2022 3
2100 3
2022 1
2022 11`.split('\n')
const result = []
const monthMap = {1 : 31, 2 : 31, 4 : 31, 5 : 30, 6 : 31, 7 : 30, 8 : 31, 9 : 31, 10 : 30, 11 : 31, 12 : 30}
for(let i = 1 ; i < input.length ; i++){
const [year, num] = input[i].split(' ').map(Number)
if(num === 3){
if(year % 4 == 0 && year != 2100){
result.push(`${year} 2 ${29}`)
}
else{
result.push(`${year} 2 ${28}`)
}
}
else{
result.push(`${num === 1 ? year - 1 : year} ${num === 1 ? 12 : num - 1} ${monthMap[num]}`)
}
}
console.log(result.join('\n'))'회고' 카테고리의 다른 글
| [개발일지] - 164 (0) | 2023.12.11 |
|---|---|
| [개발일지] - 163(주말) (0) | 2023.12.10 |
| [개발일지] - 161 (0) | 2023.12.08 |
| [개발일지] - 160 (0) | 2023.12.07 |
| [개발일지] - 159 (2) | 2023.12.06 |
