题目:

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 single10050 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(职员)的更多相关文章

  1. 【Kata Daily 190929】Password Hashes(密码哈希)

    题目: When you sign up for an account somewhere, some websites do not actually store your password in ...

  2. 【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 ...

  3. 【Kata Daily 191010】Grasshopper - Summation(加总)

    题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...

  4. 【Kata Daily 190927】Counting sheep...(数绵羊)

    题目: Consider an array of sheep where some sheep may be missing from their place. We need a function ...

  5. 【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 ...

  6. 【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 ...

  7. 【Kata Daily 190920】Square(n) Sum(平方加总)

    题目: Complete the square sum function so that it squares each number passed into it and then sums the ...

  8. 【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 ...

  9. 【Kata Daily 190918】Spacify(插空)

    题目: Modify the spacify function so that it returns the given string with spaces insertedbetween each ...

随机推荐

  1. 07 C语言常量

    常量的定义 常量是指固定的值,固定值在程序执行期间不会改变.这些固定值,又叫做字面量. 常量可以是任意的基本数据类型,比如整数常量.浮点常量.字符常量,或字符串字面值,也有枚举常量. 不要搞得太复杂, ...

  2. 《C++ primer plus》第3章练习题

    注:有的题设条件自己改动了一下,比如英寸英尺改成米和厘米,部分题目自己加了点额外要求. 1.要求用户输入身高(m),用下划线提示用户输入,将身高转化成"米"加"厘米&qu ...

  3. SHOI 2013 【扇形面积并】

    早上考的,我打了80分的部分分,出来和同学讨论的时候真想扇自己一巴掌...... 题目描述: 给定 n 个同心的扇形,求有多少面积,被至少k 个扇形所覆盖. 输入输出格式 输入格式: 第一行是三个整数 ...

  4. 制作iconfont放到自己的公共组件库

    我们公司的icon是UI提供svg,我们转成iconfont. 这里就不详细说明怎么制作svg,可以上网搜一下,https://www.iconfont.cn/help/detail?spm=a313 ...

  5. SolrCloud搭建

    什么是SolrCloud? SolrCloud是基于 solr 和 zookeeper 的分布式搜索方案,它的主要思想是使用zookeeper作为SolrCloud集群的配置信息中心,统一管理Solr ...

  6. Python+Appium自动化测试(6)-元素等待方法与重新封装元素定位方法

    在appium自动化测试脚本运行的过程中,因为网络不稳定.测试机或模拟器卡顿等原因,有时候会出现页面元素加载超时元素定位失败的情况,但实际这又不是bug,只是元素加载较慢,这个时候我们就会使用元素等待 ...

  7. 天啦噜!知道硬盘很慢,但没想到比 CPU L1 Cache 慢 10000000 倍

    前言 大家如果想自己组装电脑的话,肯定需要购买一个 CPU,但是存储器方面的设备,分类比较多,那我们肯定不能只买一种存储器,比如你除了要买内存,还要买硬盘,而针对硬盘我们还可以选择是固态硬盘还是机械硬 ...

  8. java9系列第二篇-资源自动关闭的语法增强

    我计划在后续的一段时间内,写一系列关于java 9的文章,虽然java 9 不像Java 8或者Java 11那样的核心java版本,但是还是有很多的特性值得关注.期待您能关注我,我将把java 9 ...

  9. 1-JAVA类、接口、抽象、多态

    类中全部成员变量用priviate修饰,用get获取,set设值 对于boolean类型的值,getter方法也一定要写成isXXX 的形式,而setXXX类型不变 this关键字的作用 当方法的局部 ...

  10. 基于python实现单链表代码

    1 """ 2 linklist.py 3 单链表的构建与功能操作 4 重点代码 5 """ 6 7 class Node: 8 " ...