๐ข ๋ณธ ํฌ์คํ ์ ํ์ฉ๋๋ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐ ์๋ฃ ์ถ์ฒ๋ HackerRank ์์ ๋ฐํ๋๋ค.
โ ๋ฌธ์
https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true
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
โ ํ์ด
SELECT CASE WHEN A=B AND B=C AND C=A THEN 'Equilateral'
WHEN A>=B+C OR B>=C+A OR C>=A+B THEN 'Not A Triangle'
WHEN A=B OR B=C OR A=C THEN 'Isosceles'
ELSE 'Scalene' END
FROM TRIANGLES;
* ํ์ด์์ ์ค์ํ ๊ฒ.
1) CASE WHEN ๋ฌธ์ ์กฐ๊ฑด ์์
2) ์ผ๊ฐํ์ ๊ฒฐ์ ์กฐ๊ฑด : ๊ฐ์ฅ ๊ธด ๋ณ์ ๊ธธ์ด๋ ๋๋จธ์ง ๋ ๋ณ์ ๊ธธ์ด์ ํฉ๋ณด๋ค ์๋ค
(=๊ฐ์ฅ ์งง์ ๋ณ์ ๊ธธ์ด๋ ๋๋จธ์ง ๋๋ณ์ ๊ธธ์ด์ ์ฐจ๋ณด๋ค ์ปค์ผ ํ๋ค.)
์ฒซ๋ฒ์งธ ์กฐ๊ฑด์์ ์ธ๋ณ์ ๊ธธ์ด๊ฐ ๋ชจ๋ ๊ฐ์ ๊ฒฝ์ฐ 'Euilateral' ์ง์
๋๋ฒ์งธ ์กฐ๊ฑด์์ ์ผ๊ฐํ์ด ์ฑ๋ฆฝํ์ง ์๋ ์กฐ๊ฑด์ ์ปฌ๋ผ ์ ์ธํ๋ฉฐ 'Not A Triangle'๋ก ์ง์
์ธ๋ฒ์งธ ์กฐ๊ฑด์์ ์ธ ๋ณ ์ค ๋ ๋ณ์ ๊ธธ์ด๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ์ด๋ฑ๋ณ ์ผ๊ฐํ 'Isosceles' ์ง์
๋๋จธ์ง ์ ๋ชจ๋ ์กฐ๊ฑด์ ํด๋นํ์ง ์๋ ๊ฒฝ์ฐ ๋ถ๋ฑ๋ณ ์ผ๊ฐํ 'Scalene' ์ง์
๋๋ฒ์งธ ์กฐ๊ฑด๋ฌธ์ธ '์ผ๊ฐํ ์ฑ๋ฆฝ์กฐ๊ฑด'์ด ์ธ๋ฒ์งธ, ๋ค๋ฒ์งธ ์กฐ๊ฑด๋ณด๋ค ์๋ ์ค๋ ๊ฒฝ์ฐ, ๋ฏธ๋ฆฌ ์ ์ธ๋์ง ์์ ' Isosceles'๋ Scalene๋ก ์๋ชป ์ง์ ๋ ์ ์์ผ๋ฏ๋ก CASE ์์๋ฅผ ๋ง์ถฐ ์จ์ฃผ๋ ๊ฒ์ด ์ค์ํ๋ค.
'Growth ๐ณ > Practice ๐ป' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] ์์ด์ง ๊ธฐ๋ก ์ฐพ๊ธฐ (0) | 2022.08.25 |
---|---|
[Hacker Rank] Occupations (0) | 2022.08.24 |
[Hacker Rank] Weather Observation Station 16 (0) | 2022.08.22 |
[Hacker Rank] Weather Observation Station 14 (0) | 2022.08.22 |
[Hacker Rank] The Blunder (0) | 2022.08.20 |