www.hackerrank.com/challenges/write-a-function/problem
Write a function | HackerRank
Write a function to check if the given year is leap or not
www.hackerrank.com
ํด์ปค๋ญํฌ ๊ธฐ์๊ฑฐ๋ฆฌ๋ค๊ฐ...
๋ฌธ์ ๊ฐ ์์ด์ฌ์ ์ฝ๋๋ฐ ๋ ์ค๋๊ฑธ๋ฆฌ๋๋ฏ๐ญ ์์ง๊น์ง print ์์ค์ด๋ผ ๋ฌธ์ ๊ฐ ์ด๋ ค์ด๊ฑด ์๋๋ฐ....
์ํผ ๋ฌธ์ ์์๋......
In the Gregorian calendar, three conditions are used to identify leap years:
- The year can be evenly divided by 4, is a leap year, unless:
- The year can be evenly divided by 100, it is NOT a leap year, unless:
- The year is also evenly divisible by 400. Then it is a leap year.
- The year can be evenly divided by 100, it is NOT a leap year, unless:
...๋ผ๊ณ ํ๋ค!๐
๐์ค๋ ์ด ๋๋ ค๋ฉด..
- 4๋ก ๋๋์ด๋จ์ด์ง๋ฉด ๊ธฐ๋ณธ ์ค๋
- but 4๋ก ๋๋์ด๋จ์ด์ง๋๋ฐ, ๊ทผ๋ฐ 100์ผ๋ก๋ ๋๋ ๋จ์ด์ง๋ฉด ํ๋
- but 4๋ก ๋๋ ๋จ์ด์ง๊ณ + 100์ผ๋ก ๋๋ ๋จ์ด์ง๊ณ + ๊ฒ๋ค๊ฐ! 400์ผ๋ก๋ ๋๋ ๋จ์ด์ง๋ฉด ์ค๋
์ ๋ฆฌํ์๋ฉด
3๋ฒ์ 400์ผ๋ก ๋๋ ๋จ์ด์ง๋ฉด ์ค๋ ์ด๋ผ๋ ๋ป์ด๊ณ
1์ด๋ 2๋ฅผ ๋ณด๋ฉด (4๋ก๋ ๋จ์ด์ง + 100์ผ๋ก๋ ์๋จ์ด์ง) -> ์ค๋ ์ด๋ผ๋ ๋ป์ด๋ค
๐โ๏ธ ์์ฑํ ์ฝ๋
๋๋ณด๊ธฐ
def is_leap(year):
leap = False
if year%400==0 or (year%4==0 and year%100!=0):
leap = True
return leap
year = int(input())
print(is_leap(year))
'๐๊ณต๋ถ > ํฐ ๋ฐ๊ฒฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ธ๋ผ์ฐ์ ์ ์๋ ์๋ฆฌ (0) | 2021.08.13 |
---|---|
0์ ํฉํ ๋ฆฌ์ผ (0) | 2020.12.09 |
๊ฐ์ด ๋ฐ๋ณต๋ ๋์ ์ฐ์ฐ (0) | 2020.11.11 |
ํ๋ก ํธ์๋์ SPA์ SSR (0) | 2020.11.08 |
Java vs Js (0) | 2020.11.07 |
๋๊ธ