BOJ | #2753 "윤년"

블로그 이사 완료·2022년 9월 18일
0
post-thumbnail

문제


Code

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : '.input.txt';
let input = fs.readFileSync(filePath).toString();

if ((input % 4 == 0 && (input % 100 != 0) || input % 400 == 0)) {
  console.log(1);
} else {
  console.log(0);
}

Review

윤년일 경우 1을, 윤년이 아닐 경우 0을 출력하는 문제였다.

윤년의 조건은 다음과 같다.
· 연도가 4의 배수 일때
· 연도가 100의 배수가 아닐 때 또는 400의 배수일 때

윤년의 조건만 잘 읽으면 if조건문논리 연산자 || &&를 통해 간단하게 풀 수 있는 문제였다.


profile
https://kyledev.tistory.com/

0개의 댓글