Условие
Return the number of days in month of year in the Gregorian calendar. February has 29 days in a leap year: years divisible by 4, except those divisible by 100 unless also divisible by 400. A helper function is_leap(year) keeps the code tidy.
Implement days_in_month(year, month).
Input
year: The year. month: The month, 1 (January) to 12 (December).
Output
Return the number of days.
Ограничения
1 ≤ year ≤ 9,999; 1 ≤ month ≤ 12
Примеры
Ввод:
year = 2024
month = 2
Ожидаемый вывод:
expected = 29
Ввод:
long long year = 2024;
long long month = 2;
Ожидаемый вывод:
long long expected = 29;
Ввод:
long year = 2024;
long month = 2;
Ожидаемый вывод:
long expected = 29;
Пояснение
2024 is divisible by 4 and not by 100, so it is a leap year: 29 days.
Ввод:
year = 1900
month = 2
Ожидаемый вывод:
expected = 28
Ввод:
long long year = 1900;
long long month = 2;
Ожидаемый вывод:
long long expected = 28;
Ввод:
long year = 1900;
long month = 2;
Ожидаемый вывод:
long expected = 28;
Пояснение
1900 is divisible by 100 but not 400, so it is not a leap year: 28 days.
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.