모든 챌린지
쉬움 0명 해결 정답률 0%

Season From Month and Day

Given a month name and a day, return the season of the year in the Northern Hemisphere.

배우게 될 내용

  • Validate a month name and day before using them
  • Turn a month name into a month number
  • Compare (month, day) pairs against range boundaries

문제

번역본 보기

A weather club wants a small helper for its sign-up form: members type the month of their birthday as a word (for example October) and the day as a number, and the form shows the season they were born in. The club uses these fixed dates for the Northern Hemisphere:

  • Spring: March 20 to June 20
  • Summer: June 21 to September 21
  • Autumn: September 22 to December 20
  • Winter: December 21 to March 19

All ranges include both end dates.

Implement season_from_date(month, day).

Input

month: The month as a full English name with a capital first letter, such as "March". Any other text ("march", "Mar", "") is invalid.

day: The day of the month. It is valid from 1 up to the number of days in that month; February allows 29.

Output

Return "Spring", "Summer", "Autumn" or "Winter". If the month name or the day is not valid, return "Invalid".

제약 조건

month has at most 20 characters

−1000 ≤ day ≤ 1000

예시

예시 1
입력:
month = "April"
day = 11

예상 출력:
expected = "Spring"
입력:
std::string month = "April";
long long day = 11;

예상 출력:
std::string expected = "Spring";
입력:
string month = "April";
long day = 11;

예상 출력:
string expected = "Spring";

설명

April 11 falls between March 20 and June 20, so the answer is "Spring".

예시 2
입력:
month = "February"
day = 30

예상 출력:
expected = "Invalid"
입력:
std::string month = "February";
long long day = 30;

예상 출력:
std::string expected = "Invalid";
입력:
string month = "February";
long day = 30;

예상 출력:
string expected = "Invalid";

설명

February never has 30 days, so the date is "Invalid".

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Check that the month is one of the twelve names and that the day fits that month first.

힌트 2

Comparing month first and day second lets you test whether a date is inside a range.

힌트 3

Winter wraps around the new year, so handle it as whatever is left after the other three seasons.

예상 복잡도

O(1) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.