티스토리 뷰

728x90

문제 링크

https://www.acmicpc.net/problem/25286

 

25286번: 11월 11일

11월 11일에는 농업인의 날, 가래떡 데이, 보행자의 날, 대한민국 해군 창설 기념일, 유엔참전용사 추모의 날, 빼빼로 데이 등 다양한 의미를 가진 날이다. 성현이는 11월 11일의 11일 전은 10월 31일,

www.acmicpc.net

 

풀이

JS는 Date 객체를 이용하면 간단하게 풀 수 있습니다.

다만 Date 객체는 기본적으로 로컬 타임에 맞춰버리니 UTC라고 명시해줘야 편합니다.

 

 

정답 코드

// @BOJ ------------------------------------------
const fs = require('fs');
const stdin = fs.readFileSync('/dev/stdin').toString().split('\n');
const input = (() => {
let line = 0;
const input = () => stdin[line++];
input.num = () => input().split(' ').map(Number);
input.rows = l => Array(l).fill().map(input);
input.rows.num = l => Array(l).fill().map(input.num);
return input;
})();
// Solution -----------------------------------
const solve = ([year, month]) => {
const date = new Date(Date.UTC(year, month - 1, month));
date.setUTCDate(date.getUTCDate() - month);
return [date.getFullYear(), date.getMonth() + 1, date.getDate()];
};
const solution = function () {
const t = +input();
const ans = input.rows
.num(t)
.map(solve)
.map(ymd => ymd.join(' '))
.join('\n');
console.log(ans);
};
solution();
728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/03   »
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
글 보관함