蚂蚁之死
来源:互联网 发布:mysql 控制台输出 编辑:程序博客网 时间:2024/04/29 10:53
描述:
一群蚂蚁井然有序地行进在公园野餐区,像这样:
..ant..ant.ant…ant.ant..ant.ant….ant..ant.ant.ant…ant..
突然,有蚁传来消息说,前面有一个三明治掉在了地上。蚂蚁群闻讯后飞速前进,立刻就发生了蚂蚁踩踏事件。一些跑得慢的蚂蚁被踩的身首异处,尸骨无存,像这样:
…ant…ant..nat.ant.t..ant…ant..ant..ant.anant..t
你能找出被踩死的蚂蚁有几只吗?
例如:
DeadAntCount(“ant ant ant ant”) =>0
DeadAntCount(“…ant…ant..nat.ant.t..ant…ant..ant..ant.anant..t”) =>3
DeadAntCount(null) =>0
Mycode:
using System;using System.Linq;public class Kata{ public static int DeadAntCount(string ants) { if(ants == null) return 0; int originalAnt,aliveAnt,deadAnt; int head = ants.Count(x => x == 'a'); int body = ants.Count(y => y == 'n'); int foot = ants.Count(z => z == 't'); originalAnt = Math.Max(head,Math.Max(body,foot)); aliveAnt = ants.Replace("ant","*").Count(o => o == '*'); deadAnt = originalAnt - aliveAnt; return deadAnt; }}
CodeWar:
using System;using System.Linq;public class Kata{ public static int DeadAntCount(string ants) { ants = ants?.Replace("ant", "") ?? ""; return Math.Max(ants.Count(c => c == 'a'), Math.Max(ants.Count(c => c == 'n'),ants.Count(c => c == 't'))); }}
0 0
- 蚂蚁之死
- 算法入门之蚂蚁
- 蓝桥杯之蚂蚁感冒
- 蓝桥杯之蚂蚁感冒
- 游戏童年之斗蚂蚁
- 蓝桥杯之兰顿蚂蚁
- 蓝桥杯之蚂蚁感冒问题
- 蚂蚁 算法之第二集
- 蓝桥杯之兰顿蚂蚁
- 蚂蚁
- 蚂蚁
- 蚂蚁
- 蚂蚁
- 蚂蚁
- 程序员之死
- 程序员之死
- 吃吃之死
- 显示器之死 -_-
- 为什么同样是pom文件里面的架包jar,显示的图标不一样。以及maven中snapshot快照库和release发布库的区别和作用
- Cocos2dx 场景切换 反向传值
- Fuel 9.0安装Openstack网络验证失败解决
- 关于mysql字段名和保留字冲突的问题
- [计网] C++ socket 实现miniFTP
- 蚂蚁之死
- Hadoop单机本地模式
- 2016 沈阳 1003 Recursive sequence(hdu 5950)矩阵快速幂
- 开篇
- 硬盘的存储原理和内部架构
- c++
- c语言优缺点的简单讲解
- android mvc模式再学习
- 《React-Native系列》40、 ReactNative之bundle文件瘦身