(1).백준 6845번 Federal Voting Age는 투표할 때 연령이 18세 이상인지를 계산해야 하는 문제였다.
우리나라도 6월 28일부터는 만나이 계산이 기본 방침이 되었기 때문에
언젠가 나이체크를 위해 생년월일을 체크할 때 진짜 사용할만한 느낌이 들기도 했다.
해당 방식으로 진행하려면 Today() 방식으로 해서 년, 월, 일의 차이를 비교해야 하지만
여기서는 지정일자가 있었기 때문에 target + Year/Month/Day 형태로 상수를 넣어주고
해당 일자보다 이후에 태어난 경우 성인이 아닌 것으로 처리했다.
const input = `5
1933 10 29
1989 2 28
1961 11 23
1999 12 31
1989 2 27`.split('\n')
const targetYear = 1989
const targetMonth = 2
const targetDay = 27
const result = []
for(let i = 1 ; i < input.length ; i++){
const [year, month, day] = input[i].split(' ').map(Number)
if(year < targetYear
|| (year === targetYear && month < targetMonth)
|| (year === targetYear && month === targetMonth && day <= targetDay)
){
result.push("Yes")
}
else{
result.push('No')
}
}
console.log(result.join('\n'))'회고' 카테고리의 다른 글
| [개발일지] - 80 (0) | 2023.09.18 |
|---|---|
| [개발일지] - 79(주말) (0) | 2023.09.17 |
| [개발일지] - 77 (0) | 2023.09.15 |
| [개발일지] - 76 (0) | 2023.09.14 |
| [개발일지] - 75 (0) | 2023.09.13 |
