접근 : 구현, map
Map()을 활용해 볼 수 있는 좋은 문제
Javascript
let input = require("fs")
.readFileSync("input.txt") //"/dev/stdin"
.toString()
.split("\n")
.map((val) => val.trim());
function solution(input) {
//input
let n = +input.shift();
let arr = [];
for (let i = 0; i < n; i++) {
let temp = input.shift().split(" ");
arr.push(temp);
}
let birth = new Map();
let num = [];
arr.forEach((v) => {
let year = v[3];
let month = v[2];
let day = v[1];
if (month.length === 1) {
month = "0" + month;
}
if (day.length === 1) {
day = "0" + day;
}
let temp = [year, month, day].join("");
num.push(temp);
birth.set(temp, v[0]);
});
let old = String(Math.min(...num));
let young = String(Math.max(...num));
console.log(birth.get(young));
console.log(birth.get(old));
}
solution(input);
'코딩테스트(알고리즘) > baekjoon' 카테고리의 다른 글
[baekjoon] 1769 3의 배수 (Javascript) (0) | 2022.06.24 |
---|---|
[baekjoon] 1969 DNA (Javascript) (0) | 2022.06.24 |
[baekjoon] 18111 마인크래프트 (Javascript) (0) | 2022.06.23 |
[baekjoon] 2563 색종이 (Javascript) (0) | 2022.06.22 |
[baekjoon] 8979 올림픽 (Javascript) (0) | 2022.06.22 |