公式

A - 季節の名前 / Season Names 解説 by admin

swe-2-high

Explanation

This problem simply asks us to determine which season the given month \(M\) belongs to.

According to the table in the statement:

  • If \(3 \leq M \leq 5\), output Spring
  • If \(6 \leq M \leq 8\), output Summer
  • If \(9 \leq M \leq 11\), output Autumn
  • If \(M = 12, 1, 2\) (i.e., anything else), output Winter

We check these conditions in order and print the corresponding string.

Proof of Correctness

For any integer \(M\) with \(1 \leq M \leq 12\), \(M\) belongs to exactly one of the sets \(\{3,4,5\}\), \(\{6,7,8\}\), \(\{9,10,11\}\), \(\{12,1,2\}\). Since the conditional branches check these mutually exclusive ranges in order, exactly one season name is selected and printed for any valid \(M\). Therefore the output always matches the table in the statement.

Complexity

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