https://www.acmicpc.net/problem/2753

 

2753번: 윤년

연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오. 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. 예를 들어, 2012년은 4의 배수이면서

www.acmicpc.net

using System;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            // 2012 >> 윤년 4의배수o, 100배수x
            // 1900 >>      100배수o, 400배수x
            // 2000 >>      400배수o

            string year = Console.ReadLine();
            int _year = int.Parse(year);

            if (_year % 4==0) { //윤년o
                if (_year % 100 != 0)
                {
                    Console.WriteLine("1");
                }
                else if (_year % 400 == 0)
                {
                    Console.WriteLine("1");
                }
                else
                {
                    Console.WriteLine("0");
                }
            }
            else {  // 윤년x
                Console.WriteLine("0");
            }

        }
    }
}

+ Recent posts