簡単 4件解決済み 正答率66.7%

Ticket Price by Age

Choose a cinema ticket price from the visitor's age.

このチャレンジで学べること

  • Choose a value from age ranges
  • Write non-overlapping conditions
  • Test boundary ages

問題

翻訳を表示

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

The price depends on which age band the visitor falls into.

ヒント 2

Check the youngest and oldest special cases before the middle ranges.

ヒント 3

Pay attention to the exact endpoints so ages 3, 13, and 65 get the correct prices.

目安の計算量

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

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 RCRiccardo Corti Python 1,212 ms - 4/5 コードを見る
2 LMLaura Mahlow Python 1,214 ms - 5/5 コードを見る
3 ДЗДавид Зайдулин Python 1,224 ms - 4/5 コードを見る
4 PKPornchai Kaewkrabil Go 1,510 ms - 4/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が4件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。