문제 링크: https://www.acmicpc.net/problem/2753
백준 조건문 3단계 - 2753번 윤년을 풀어보았다.
풀이: 문제 조건대로 풀면 되지만, 조건을 잘 배분하는 게 중요하다.
C++
#include <iostream>
using namespace std;
int main() {
int year;
cin >> year;
if(year%4==0)
{
if(year%400==0)
{
cout<<1;
}
else if(year%100!=0)
{
cout<<1;
}
else
{
cout<<0;
}
}
else
{
cout<<0;
}
}
Python
year=int(input())
if(year%4==0):
if(year%400==0): print(1)
elif(year%100!=0): print(1)
else: print(0)
else: print(0)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
if(a%4==0)
{
if(a%400==0) System.out.println(1);
else if(a%100!=0) System.out.println(1);
else System.out.println(0);
}
else System.out.println(0);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
알람 시계 풀이 (0) | 2022.12.30 |
---|---|
사분면 고르기 풀이 (0) | 2022.12.30 |
시험 성적 풀이 (0) | 2022.12.30 |
두 수 비교하기 풀이 (0) | 2022.12.30 |
새싹 풀이 (0) | 2022.12.30 |