//能被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> #include <stdbool.h> static bool is_leap_year(int n) { if ((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)) { return true; } return false; } int main() { int n = 0; scanf("%d", &n); printf("%s", is_leap_year(n) ? "yes" : "no"); return 0; }
use std::io; fn main() { let mut stdin = String::new(); io::stdin() .read_line(&mut stdin) .expect(""); let n:i64 = stdin .trim() .parse() .expect(""); if n % 400 == 0 { println!("yes"); } else if n % 4 == 0 && n % 100 != 0 { println!("yes"); } else { println!("no"); } }
#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; }