A - 季節の名前 / Season Names 解説 by admin 印刷ページ
swe-2-highExplanation
The month-to-season mapping is fully fixed by the statement, so we just branch on \(M\). Months \(3\)–\(5\) are Spring, \(6\)–\(8\) are Summer, \(9\)–\(11\) are Autumn, and the remaining months (\(12\), \(1\), \(2\)) are Winter.
The program uses an if / else if / else chain: it checks whether \(M\) is between \(3\) and \(5\), then between \(6\) and \(8\), then between \(9\) and \(11\), and prints Winter otherwise. Conditions are evaluated top to bottom, and every month from \(1\) to \(12\) falls into exactly one range, so the correct name is always printed.
At most \(3\) comparisons are made, so both time and space complexity are \(O(1)\).
投稿日時:
最終更新: