|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ooxx7788 于 2017-4-26 14:10 编辑
该死的电影院今天售票员全都放假。只能依靠电影院自动售票机进行购票,单张票价为25元。而售票机内没有钱,因此只能靠收入的钱去找零。售票机只能单张销售。(这电影院为什么不倒闭算了。)
现有的货币面值为100,50,25三种。现在有n个人需要买票,且排队顺序不许变,请你根据他们手中的钱计算出,售票机能否进行找零。可以则返回yes,不可以则返回no
- def tickets(people):
- # your code
- return ?
复制代码- 例:
- tickets([25,25,50]) --->'yes'
- tickets([25,50]) --->'yes'
- tickets([25,100]) --->'no'
- tickets([50,50,100]) --->'no'
- tickets([25,50,100]) --->'no'
- print(tickets([100, 50, 25, 25])) --->'no' # 由于排队数序不许变,这个本可以交易的组合无法进行交易。
复制代码
- 给出一段测试代码,避免你们自己去兑答案了。
- 以下代码保存为test.py,后import可用
- def assert_equals(func, target):
- if func == target:
- print('Success!')
- else:
- print('Fail!{0} not equals {1}'.format(func, target))
复制代码
- test.assert_equals(tickets([25, 25, 50]), 'YES')
- test.assert_equals(tickets([25, 100]), 'NO')
- test.assert_equals(tickets([25, 25, 25, 25, 25, 25, 25, 25, 25, 25]), 'YES')
- test.assert_equals(tickets([50, 50, 50, 50, 50, 50, 50, 50, 50, 50]), 'NO')
- test.assert_equals(tickets([100, 100, 100, 100, 100, 100, 100, 100, 100, 100]), 'NO')
- test.assert_equals(tickets([25, 25, 25, 25, 50, 100, 50]), 'YES')
- test.assert_equals(tickets([50, 100, 100]), 'NO')
- test.assert_equals(tickets([25, 25, 100]), 'NO')
- test.assert_equals(tickets([25, 25, 50]), 'YES')
- test.assert_equals(tickets([25, 25, 25, 25, 25, 25, 25, 50, 50, 50, 100, 100, 100, 100]),'NO')
- test.assert_equals(tickets([25, 100]), 'NO')
- test.assert_equals(tickets([50, 50, 100]), 'NO')
- test.assert_equals(tickets([25, 50, 100]), 'NO')
- test.assert_equals(tickets([25, 25, 50, 50, 100]), 'NO')
- test.assert_equals(tickets([100, 50, 25, 25]), 'NO')
复制代码
好了,下面是我的答案,但是我也不保证对,只是以上测试能通过。
|
|