問題
A cinema charges by age: children under 3 are free, ages 3–12 pay 5, ages 13–64 pay 12, and 65 or older pay 7.
Implement ticket_price(age).
Input
age: The visitor's age in years.
Output
Return the ticket price.
制約
0 ≤ age ≤ 120
例
例 1
入力:
age = 10
期待される出力:
expected = 5
入力:
long long age = 10;
期待される出力:
long long expected = 5;
入力:
long age = 10;
期待される出力:
long expected = 5;
解説
10 is between 3 and 12, so the price is 5.
例 2
入力:
age = 70
期待される出力:
expected = 7
入力:
long long age = 70;
期待される出力:
long long expected = 7;
入力:
long age = 70;
期待される出力:
long expected = 7;
解説
70 is 65 or older, so the senior price of 7 applies.
解き方のヒント
まずは自分で考えてから、ヒントを 1 つずつ開いてみましょう。
ヒント 1
料金は、来場者がどの年齢帯に入るかで決まる。
ヒント 2
真ん中の範囲より先に、最年少と最年長の特別ケースを確認する。
ヒント 3
3、13、65 のような境界が正しい価格になるよう、端点を厳密に見る。
目安の計算量
時間 O(1)、追加メモリ O(1)
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。