首页 > 试题广场 >

判断闰年

[编程题]判断闰年
  • 热度指数:25591 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定一个整数 n,判断其是否为闰年。闰年的判定规则如下:
\hspace{23pt}\bullet\,如果 n 能被 400 整除,则为闰年;
\hspace{23pt}\bullet\,否则如果 n 能被 4 整除且不能被 100 整除,则为闰年;
\hspace{23pt}\bullet\,否则,不是闰年。

输入描述:
\hspace{15pt}在一行中输入一个整数 n,满足 \left(1 \leqq n \leqq 2018\right)


输出描述:
\hspace{15pt}输出一个字符串,若 n 为闰年,输出 "yes"(不含双引号);否则输出 "no"(不含双引号)
示例1

输入

2000

输出

yes

说明

2000 能被 400 整除,因此是闰年。
示例2

输入

1900

输出

no

说明

1900 能被 100 整除但不能被 400 整除,因此不是闰年。
n = int(input())
if 1 <= n <=2018:
    if (n%4 == 0 and n%100 !=0):
        print("yes")
    elif (n%400 == 0):
        print("yes")
    else:
        print("no")
发表于 2022-07-07 13:20:12 回复(0)
n = int(input())
print('yes' if n%400 == 0&nbs***bsp;(n%100 != 0 and n%4 ==0) else 'no')

发表于 2022-03-26 16:51:52 回复(0)
n = int(input())
if n >= 1 and n <=2018:
    if (n % 4 == 0 and n % 100 != 0)&nbs***bsp;n % 400 == 0:
        print("yes")
    else:
        print("no")
else:
    print()

发表于 2022-03-26 09:53:23 回复(0)
year= int(input())
if year % 400 == 0:
    print('yes')
elif (year % 4 == 0) and (year % 100 != 0):
    print('yes')
else:
    print('no')
发表于 2022-03-17 19:16:16 回复(1)
while True:
    try:
        year = int(input())
        if year%100 == 0 and (year//100)%4 == 0:
            print('yes')
        elif year%100 == 0 and (year//100)%4 != 0:
            print('no')
        elif year%100 != 0 and year%4 == 0:
            print('yes')
        else:
            print('no')
    except:
        break
发表于 2022-02-26 18:15:15 回复(0)