【Kata Daily 190906】Vasya - Clerk(职员)
题目:
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single100
, 50
or 25
dollars bill. A "Avengers" ticket costs 25 dollars
.
Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.
Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Return YES
, if Vasya can sell a ticket to each person and give the change. Otherwise return NO
.
-----------------------------------------------------------------------------------------------------------
找零钱的题目,客人中会出现25,50,100面值的钞票,电影票25块钱。问一条队中,店员能不能卖完电影票而且不用另外找零钱。
解题办法:
看下网友的解题思路:
def tickets(people):
n25, n50, n100 = 0, 0, 0
for i in people:
if i == 25:
n25 += 1
elif i == 50:
n25 -= 1
n50 += 1
elif i == 100 and n50>0:
n25 -= 1
n50 -= 1
elif i == 100 and n50==0:
n25 -= 3
if n25<0 or n50<0:
return "NO"
else:
return "YES"
解读:利用钱包中钱的个数来判断是否能够找得开零钱。并对100元的情况进行了分别处理,即优先使用50元来找零。
还有一种没有通过测试的算法:
def tickets(people):
sum, change,a = 0, 0, ""
for i in people:
sum += 25
change = i - 25
sum -= change
if sum < 0:
a = "NO"
else:
a = "YES"
return a
疑惑:举不出例子来说明该算法的错误之处。另外此段算法给到你,你该如何编写测试用例?
【Kata Daily 190906】Vasya - Clerk(职员)的更多相关文章
- 【Kata Daily 190929】Password Hashes(密码哈希)
题目: When you sign up for an account somewhere, some websites do not actually store your password in ...
- 【Kata Daily 191012】Find numbers which are divisible by given number
题目: Complete the function which takes two arguments and returns all numbers which are divisible by t ...
- 【Kata Daily 191010】Grasshopper - Summation(加总)
题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...
- 【Kata Daily 190927】Counting sheep...(数绵羊)
题目: Consider an array of sheep where some sheep may be missing from their place. We need a function ...
- 【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)
题目: In this simple exercise, you will create a program that will take two lists of integers, a and b ...
- 【Kata Daily 190923】Odder Than the Rest(找出奇数)
题目: Create a method that takes an array/list as an input, and outputs the index at which the sole od ...
- 【Kata Daily 190920】Square(n) Sum(平方加总)
题目: Complete the square sum function so that it squares each number passed into it and then sums the ...
- 【Kata Daily 190919】Sort Out The Men From Boys(排序)
题目: Scenario Now that the competition gets tough it will Sort out the men from the boys . Men are th ...
- 【Kata Daily 190918】Spacify(插空)
题目: Modify the spacify function so that it returns the given string with spaces insertedbetween each ...
随机推荐
- 035 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 02 多重if结构
035 01 Android 零基础入门 01 Java基础语法 04 Java流程控制之选择结构 02 多重if结构 本文知识点:Java中的多重if结构 选择结构回顾 if选择结构 注意: 1.条 ...
- 《C++ primerplus》第13章练习题
1.对CD类的派生练习.基类CD类存储作者和作品号等信息,派生类Classic额外增加一格"主要作品"的信息.主函数使用拷贝构造函数.按引用传递参数的函数和指针来测试基类和派生类的 ...
- Github 太狠了,居然把 "master" 干掉了!
前段时间栈长有看到 Github 和 master 分支变更的新闻,当时没有注意细节,直到今天我创建仓库时: 看了半天感觉有点不对劲啊... 怎么 master 不见了,之前默认主干分支名称都是叫 m ...
- springboot利用redis做缓存
首先 配置redis redis: password: 123456 host: 127.0.0.1 port: 6379 #103.249.252.109:10086 expireSeconds: ...
- 多测师讲解unittest介绍及自动化测试实现流程_高级讲师肖sir
unittest框架介绍 unittest框架是python中一个标准的库中的一个模块,该模块包括许多的类如 test case类.test suit类.texttest runner类.textte ...
- wine实用经验教程
本篇讲类unix系统下的用以模拟运行Windows程序的wine.会从普通使用者的比较实用的角度去讲.有专为国内用户准备的内容. 本篇面向有Linux经验但对wine不熟悉的人. wine可靠吗?该不 ...
- Tensorflow学习笔记No.7
tf.data与自定义训练综合实例 使用tf.data自定义猫狗数据集,并使用自定义训练实现猫狗数据集的分类. 1.使用tf.data创建自定义数据集 我们使用kaggle上的猫狗数据以及tf.dat ...
- fedora30平台安装docker 19.03
一,下载docker 1,说明:docker的打包对于fedora的支持很及时, 所以在fedora 30/31上都可以直接使用官方的rpm包 下载地址: https://download.docke ...
- Python函数递归调用
函数的递归调用: 是函数嵌套调用的一种特殊形式 具体是指: 在调用一个函数的过程中又直接或间接地调用到了本身 # 直接调用本身 def func(): print('我是func') func() f ...
- C# 微信共享收货地址 V1.6
//使用微信共享收货地址在跳转到当前页面的路径上必须要包含Code和state这两个获取用户信息的参数//例如 <a href="ProductOrder.aspx?OID=<% ...