公式

A - 季節の名前 / Season Names 解説 by admin 印刷ページ

gpt-6-astra-medium

Overview

This problem asks us to output the English name of the season corresponding to an input month \(M\). We can store the mapping from months to seasons in a dictionary and retrieve the answer.

Analysis

There are only \(12\) possible months, from month \(1\) to month \(12\), and the season for each month is defined in the problem statement. Therefore, by pre-registering the season for every month, we can directly obtain the answer from the input month.

The correspondence is as follows:

Month English name of season
\(1, 2, 12\) Winter
\(3, 4, 5\) Spring
\(6, 7, 8\) Summer
\(9, 10, 11\) Autumn

A naive approach using conditional branches is also sufficiently fast and correct. However, because winter spans across month \(12\) and months \(1, 2\), care is required when writing the conditions.

In this implementation, we use a dictionary with the months as keys and the English season names as values, retrieving the answer without needing range checks.

Algorithm

  1. Read the input as an integer and store it in the variable m.
  2. Create a dictionary table that maps each month to its corresponding English season name.
  3. Output table[m].

For example, if the input is \(7\), table[7] is Summer, so we output Summer.

According to the constraints, the input is guaranteed to be between \(1\) and \(12\), inclusive, and the dictionary contains the correct season for all of these months. Therefore, this procedure will always yield the correct answer.

Complexity

  • Time Complexity: \(O(1)\)
  • Space Complexity: \(O(1)\)

The number of elements in the dictionary is always \(12\), so the amount of computation and memory required does not increase with the input.

Implementation Notes

  • Since the result of input() is a string, convert it to an integer using int(input()). The keys in the dictionary are also registered as integers.

  • Do not forget that month \(12\) is also Winter.

  • Make sure that the English name to be printed matches the notation in the problem statement, including uppercase and lowercase letters.

    Source Code

# 問題文から独立に実装: 月から季節を表で引く
m = int(input())
table = {1: "Winter", 2: "Winter", 3: "Spring", 4: "Spring", 5: "Spring",
         6: "Summer", 7: "Summer", 8: "Summer", 9: "Autumn", 10: "Autumn", 11: "Autumn", 12: "Winter"}
print(table[m])

This editorial was generated by gpt-6-astra-medium.

投稿日時:
最終更新: