A year y is given. Print "leap" if it is a leap year under the Gregorian rules below, otherwise "common". A year divisible by 4 is a leap year, except that a year divisible by 100 is not, except that a year divisible by 400 is again a leap year. For example, 2024 is a leap year, 1900 is common, 2000 is a leap year.
Input
one integer y (1 ≤ y ≤ 10000)
Output
"leap" or "common"
Example 1 · stdin
2000
stdout
leap
Example 2 · stdin
1900
stdout
common
main.py
Error List00F8 ↓ · ⇧F8 ↑
Input (stdin)
When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).
$ Ready
Open this on a computer to write and run code. On mobile you can read the problem and the solutions.
In other languagesShow solutions by language · 8 languages
Forgetting the 100 and 400 rules is the most common mistake. Checking only y % 4 == 0 makes 1900 a leap year; adding only the 100 rule makes 2000 a common year. In one line: (y % 4 == 0 && y % 100 != 0) || y % 400 == 0. The spelling of and/or differs: Python uses and, or, not; the other 7 languages (Craykon included) use &&, ||, !. In every language && binds tighter than ||, but parentheses keep readers from guessing. Craykon: if (…) { } else { }.
Pythonmain.py · 5 lines
y = int(input())if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0: print("leap")else: print("common")
JavaScriptmain.js · 3 lines
const y = Number(require("fs").readFileSync(0, "utf8").trim());const leap = (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;console.log(leap ? "leap" : "common");
TypeScriptmain.ts · 4 lines
import { readFileSync } from "node:fs";const y: number = Number(readFileSync(0, "utf8").trim());const leap: boolean = (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;console.log(leap ? "leap" : "common");
JavaMain.java · 9 lines
import java.util.Scanner;public class Main { public static void main(String[] args) { int y = new Scanner(System.in).nextInt(); boolean leap = (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; System.out.println(leap ? "leap" : "common"); }}
C#Main.cs · 11 lines
using System;class Program{ static void Main() { int y = int.Parse(Console.ReadLine()); bool leap = (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; Console.WriteLine(leap ? "leap" : "common"); }}