//能被4整除但不能被100整除的年份是闰年,能被400整除的年份也是闰年。 //2024年是闰年,因为它可以被4整除,但不能被100整除。 //1900年不是闰年,因为它可以被100整除,但不能被400整除。 //1600年是闰年,可以被4整除,也能被100整除,但它同时也能被400整除。 #include <stdio.h> int main() { int a = 0; scanf("%d", &a); if(a % 400 == 0) { printf("yes\n"); } else { if(a % 4 == 0 && a % 100 != 0) { printf("yes\n"); } else { printf("no\n"); } } return 0; }
#include <stdio.h> int main() { int n; while(1){ if(scanf("%d",&n)!=1){ while(getchar()!='\n'); continue; } while(getchar()!='\n'); if(n < 1 || n > 2018){ continue;//如果输入错误就重新开始while的循环,直到正确. } if((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)){ printf("yes\n"); }else{ printf("no\n"); } break; } return 0; }
a = int(input()) if (a%4==0 and a%100!=0)&nbs***bsp;(a%400==0): print("yes") else: print("no") |