Skip to content

Commit 146c9db

Browse files
[BOJ] 1340 연도 진행바 (S5)
1 parent 82ec0b8 commit 146c9db

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

서정우/6주차/260206.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require("fs");
2+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
3+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
4+
5+
const line = input[0];
6+
7+
const [MD, YT] = line.split(", ");
8+
9+
const [M, D] = MD.split(" ");
10+
const [Y, T] = YT.split(" ");
11+
const [hours, minutes] = T.split(":").map(Number);
12+
13+
const monthMap = {
14+
January: 1,
15+
February: 2,
16+
March: 3,
17+
April: 4,
18+
May: 5,
19+
June: 6,
20+
July: 7,
21+
August: 8,
22+
September: 9,
23+
October: 10,
24+
November: 11,
25+
December: 12,
26+
};
27+
28+
const month = monthMap[M];
29+
const day = Number(D);
30+
const year = Number(Y);
31+
32+
const isLeapYear = year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
33+
const days = [31, isLeapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
34+
const totalMinutes = isLeapYear ? 366 * 24 * 60 : 365 * 24 * 60;
35+
36+
const currentDays =
37+
days.reduce((acc, cur, idx) => (idx < month - 1 ? acc + cur : acc), 0) + day - 1;
38+
const currentHours = currentDays * 24 + hours;
39+
const currentMinutes = currentHours * 60 + minutes;
40+
41+
const percent = (currentMinutes / totalMinutes) * 100;
42+
console.log(
43+
Intl.NumberFormat("en-US", { minimumFractionDigits: 1, maximumFractionDigits: 14 }).format(
44+
percent,
45+
),
46+
);

서정우/input.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
abc
2-
bca
1+
December 31, 2007 23:59

0 commit comments

Comments
 (0)