【hackerrank】Type of Triangle
题目如下:
Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:
- Equilateral: It's a triangle with sides of equal length.
- Isosceles: It's a triangle with sides of equal length.
- Scalene: It's a triangle with sides of differing lengths.
- Not A Triangle: The given values of A, B, and C don't form a triangle.
Input Format
The TRIANGLES table is described as follows:
Each row in the table denotes the lengths of each of a triangle's three sides.
Sample Input
Sample Output
Isosceles
Equilateral
Scalene
Not A Triangle
Explanation
Values in the tuple form an Isosceles triangle, because .
Values in the tuple form an Equilateral triangle, because . Values in the tuple form a Scalene triangle, because .
Values in the tuple cannot form a triangle because the combined value of sides and is not larger than that of side .
解题思路:主要是根据三个边长之间的关系来判断三角形的种类,注意判断的顺序是:不是三角形,等边三角形,等腰三角形,其他三角形。
代码如下:
- /*
- Enter your query here.
- */
- select
- case
- when (A+B) <= C or (A+C) <= B or (B+C) <= A then 'Not A Triangle'
- when (A=B) and (B=C) and (A=C) then 'Equilateral'
- when (A=B) or (A=C) or (B=C) then 'Isosceles'
- else 'Scalene'
- END
- from
- TRIANGLES;
【hackerrank】Type of Triangle的更多相关文章
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- 【Leetcode】【Easy】Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【LeetCode】611. Valid Triangle Number 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/valid-tri ...
- 【LeetCode】812. Largest Triangle Area 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 三重循环 组合函数 日期 题目地址:https:// ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- 【leetcode】Pascal's Triangle I & II (middle)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【python】type()、instance()
>>> a=520 >>> type(a) <class 'int'> >>> a=' >>> type(a) &l ...
- 【HackerRank】How Many Substrings?
https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...
随机推荐
- 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_04.mybatis概述
- svn访问版本库时一直提示: please wait while the repository browser is initializing
最近不知道做了什么操作,原来正常的SVN Check In/Out都无法正常操作. 正常Check In的动作,几秒钟就会操作完成,但是我却等了好久好久,然后提示Connection timed ou ...
- VirtualBox主机虚拟机互通
首先使用的是桥接模式,桥接模式相当于是使用Hub来把主机以及虚拟机进行关联: 然后就是选择“界面名称”,这里吐槽一下,这里其实是“Interface Name”,Interface代表的是网卡的接口, ...
- golang 导出CSV文件中文乱码的问题
golang 导出CSV文件中文乱码的问题 解决办法: 在csv文件的开头写入 UTF-8 BOM // 创建文件 dstf, err := os.Create("./data/" ...
- Jmeter运行后,查看结果树中的响应数据出现中文乱码。
参考:https://blog.csdn.net/qq_15228737/article/details/82597482 https://baike.baidu.com/item/UTF-8/481 ...
- SpringBoot项目启动时执行初始化操作
SpringBooot中的CommandLineRunner接口会在所有Spring Beans初始化之后,SpringApplication.run()之前执行. 1.添加pom引用 <?xm ...
- 牛客练习赛46 E 华华和奕奕学物理 (树状数组)
https://ac.nowcoder.com/acm/contest/894/E 一开始写了一个简单的模拟 通过率只有5%...... 看题解真的理解了好久!!肥宅大哭orz 题解如下 最后一句:“ ...
- 数位DP 计划
通常的数位dp可以写成如下形式: [cpp] view plain copy int dfs(int i, int s, bool e) { if (i==-1) return s==target_s ...
- Windows下spark1.6.0本地环境搭建
由于spark是用scala编写的,且需要jdk的环境支撑,所以本地spark环境的搭建需要四个步骤:JDK的安装,scala的安装,hadoop的配置,spark的配置. 一.jdk的安装与环境变量 ...
- Kotlin学习(5)类型系统
可空性(避免空指针异常) /* *这个函数的参数代表传入一个String类型变量的实例,这代表它不可以为空 */ fun a(str:String){ println(str) } //这样调用a() ...