【Kata Daily 190927】Counting sheep...(数绵羊)
题目:
Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).
For example,
[True, True, True, False,
True, True, True, True ,
True, False, True, False,
True, False, False, True ,
True, True, True, True ,
False, False, True, True]
The correct answer would be 17.
Hint: Don't forget to check for bad values like null
/undefined
解题办法:
def count_sheeps(arrayOfSheeps):
sum = 0
for x in arrayOfSheeps:
if x:
sum += 1
return sum
其他解法:
def count_sheeps(arrayOfSheeps):
return arrayOfSheeps.count(True)
知识点:
1、计算s数量可以使用l.count(s)
【Kata Daily 190927】Counting sheep...(数绵羊)的更多相关文章
- Counting sheep...
Counting sheep... Description: Consider an array of sheep where some sheep may be missing from their ...
- 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDU-2952 Counting Sheep (DFS)
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- HDU 2952 Counting Sheep(DFS)
题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...
- HDU2952:Counting Sheep(DFS)
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- Hdu2952 Counting Sheep 2017-01-18 14:56 44人阅读 评论(0) 收藏
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- ACM HDU-2952 Counting Sheep
Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 洛谷 P3184 [USACO16DEC]Counting Haybales数草垛
P3184 [USACO16DEC]Counting Haybales数草垛 题目描述 Farmer John has just arranged his NN haybales (1 \leq N ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
随机推荐
- 048 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 10 案例——阶乘的累加和
048 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 10 案例--阶乘的累加和 本文知识点:通过案例练习嵌套循环应用 案例练习--阶乘的累加和 案例题目 ...
- Arduino 多线程简单代码
转载: 1. https://www.csdn.net/gather_27/MtTaggzsMDExMS1ibG9n.html 2. https://v.youku.com/v_show/id ...
- 《C++ primer plus》第5章练习题
1.输入两个整数,输出两个整数之间所有整数的和,包括两个整数. #include<iostream> using namespace std; int main() { int num1, ...
- [BJWC 2011]元素
题目大意: 你有n个二元组(x,y),要求从中任取几个,使得x的值亦或起来不为0,且y之和最大. 题解: 显然是以x来构造线性基的,然而加入元素的个数是有限制的,那当然就是大的先来喽,排个序就OK啦! ...
- javaagent+asm破解censum
内容介绍 最近在学习字节码相关知识,了解到通过ASM字节码改写技术来做破解一些软件破解,非常感兴趣,本文记录一下破解 Censum的过程(仅个人学习使用). 之前也写过一篇暴力破解Censum的文章, ...
- 收到DE2+LCM+ D5M套件,拾回DE2,努力,奋进!
今天收到磐转寄的查无此人的DE2二手开发套件,准备用它来做科研验证!今天天是快学的第一天,参加电子设计竞赛会议.开集体会!
- mysql5.7.23 解压版 密码忘记了咋办??
mysql 5.7.23 err文件: 查看log中保存的 密码 记下密码,重新启动MySQL服务,并进入CMD命令行,在此使用mysql -u root -p登陆,键入密码 进入数据库后,使用se ...
- MeteoInfoLab脚本示例:TRMM 2A12 HDF数据
TRMM 2A12 HDF数据是卫星观测的SWATH数据(轨道数据),比格点数据处理起来要麻烦一些.数据的经纬度保存在geolocation变量中,需要先将经纬度数据读出来(均为2维数组),然后读取云 ...
- day18 Pyhton学习 内置函数最后七个
1. enumerate 枚举函数 for i in enumerate(['a','b','c'],1): print(i)#(1, 'a')(2, 'b')(3, 'c') goods_lst= ...
- C++分隔字符串split
split C++标准库中没有提供split分隔字符串的函数,哎. 实现一 下面的实现需要指定分隔符的集合delimiters,以及是否将连续的分隔符看作同一个分隔compress : enum cl ...