Valid dates P58459


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

html

Write a function that tells if the date defined by a day d, month m and year y is valid or not.

Interface

C++
bool is_valid_date(int d, int m, int y);
C
int is_valid_date(int d, int m, int y);
Java
public static boolean isValidDate(int d, int m, int y);
Python
is_valid_date(d, m, y) # returns bool
 
is_valid_date(d: int, m: int, y: int) -> bool

To write this function, it is convinient to use the function for leap years of the exercise ‍.

Precondition The parameter y is between 1800 and 9999, both included.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    is_valid_date(29, 2, 2000) → true
    is_valid_date(29, 2, 3000) → false
    is_valid_date(-3, 14, 2000) → false
    is_valid_date(1, -10, 1984) → false
  • Information
    Author
    Jordi Petit
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++ Java Python