【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 ...
随机推荐
- 《C++primerplus》第11章练习题
1.修改程序清单11.5(随机漫步),使之以特定的格式将结果写入文件中. //vector.h -- Vector Class #ifndef _VECTOR_H_ #define _VECTOR_H ...
- 【题解】 P2734 [USACO3.3]游戏 A Game
\(\color{purple}{Link}\) \(\text{Solution:}\) 考虑区间\([l,r]\)的最优解.显然它可以由\([l+1,r]\)或\([l,r-1]\)转移而来.至此 ...
- Vue学习使用系列九【axiox全局默认配置以及结合Asp.NetCore3.1 WebApi 生成显示Base64的图形验证码】
1:前端code 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta char ...
- [Docker]linux异常关机,docker镜像丢失
在运行中的docker容器遇到意外情况,可能会自动终止运行,例如磁盘空间不足. 解决办法: 找到/var/lib/docker/containers文件夹下的所有容器ID 执行命令,查看容器信息 ,找 ...
- 初试Python
01 Python简介 Python是一种跨平台的计算机程序设计语言.于1989年开发的语言,创始人范罗苏姆(Guido van Rossum),别称:龟叔(Guido). python具有非常多并且 ...
- Convert to Ones CodeForces(超水题)
题目大意:给你几个数,这些数里面只有0或1,你有两种操作:1.把一段区域内的所有数前后交换位置.2.把一段区域内所有数取反.(区域可大可小,可以是所有数也 ...
- BOOST库 消息队列
直接贴实验代码: /******* boost 消息队列 **********/ #if 1 #include <boost/thread/thread.hpp> #include < ...
- go函数可见性
可见性 可见性,包内任何变量或函数都是能访问的.包外的话,首字母大写是可导出的,能够被其他包访问或者调用,小写表示是私有的,不能被外部包访问或调用
- linux(centos8):查看操作系统的当前版本(os/kernel/bash)
一,查看redhat系操作系统的版本: 适用于centos/fedora/rhel等 [root@centos8 ~]# cat /etc/redhat-release CentOS Linux re ...
- Django采坑日志(django2.0)
使用Mariadb时出现的问题 "Unknown system variable 'transaction_isolation'" 解决办法:修改django/db/backend ...