Is this a triangle? -- 7kyu
来源:互联网 发布:lol徐老师淘宝网站 编辑:程序博客网 时间:2024/06/01 14:35
原题http://www.codewars.com/kata/is-this-a-triangle/train/cpp
题目
Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case.
(In this case, all triangles must have surface greater than 0 to be accepted).
分析
*三边构成三角形条件:都要满足两边之和大于第三边,两边之差小于第三边并且边需要大于0,所以负数和0排除需要那么就可以推导出两种判断方式:
1.A + b> C和A + C> b和b + C> A
2.ab
代码
namespace Triangle{ bool isTriangle(int a, int b, int c) { return a-b<c && b-c<a && c-a<b; }};
namespace Triangle{ bool isTriangle(int a, int b, int c) { long la(a),lb(b),lc(c); return a>0 and b>0 and c>0 and la-lb<lc and la-lc<lb and lb-lc<la and la+lb>lc and la+lc>lb and lb+lc>la; }};作者:jdzhangxin链接:http://www.jianshu.com/p/ccbbaa81a9db來源:简书著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
阅读全文
0 0
- Is this a triangle? -- 7kyu
- Parts of a list -- 7 kyu
- This is a test
- this is a demo:)
- This is a test
- This is a test
- This is a test
- this is a test
- This is a test
- This is a test~!
- this is a test
- This is a test
- This is a Test
- This is a triumph!
- This is a test
- This is a test
- This is a test
- this is a test
- .NET从入门到放弃之C#反射
- numpy中,矩阵的三种转置transpose、getT、getH的区别
- Openwrt学习笔记 通用固件 make menuconfig配置
- Android 关闭软键盘
- C++命名空间namespace
- Is this a triangle? -- 7kyu
- HDU 2612 Find a way——bfs
- 【C】表达式
- Netty in action—Netty传输服务
- MONGODB资料整理
- 作用域新学习
- 洛谷1120 小木棍 [数据加强版] dfs+剪枝(史上最详尽)
- 机器学习笔记-神经网络中激活函数(activation function)对比--Sigmoid、ReLu,tanh
- GCD HDU