Post

[BaekJoon] 2753번 - 윤년 [Java][C++]

[BaekJoon] 2753번 - 윤년 [Java][C++]

문제 링크


1. 아이디어


주어진 연도가 윤년인지 구하는 문제로 4의 배수이면서 100의 배수가 아닌 경우와 400의 배수인 경우 윤년으로 판단하도록 조건식을 구성하면 된다.


2. 코드


1. 풀이 [Java]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int y = Integer.parseInt(br.readLine());

        if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}


2. 풀이 [C++]

1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int y;
    cin >> y;
    cout << (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}

3. 디버깅


없음.


4. 참고


없음.


This post is licensed under CC BY 4.0 by the author.