일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Level2
- 코딩테스트
- join
- 완전탐색
- import re
- time complexity
- Growth hacking
- programmers
- tableau
- LeetCode
- sql
- Queue
- coding
- lambda
- 조합
- mysql
- AARRR
- lv4
- collections
- level4
- coding test
- 파이썬
- counter
- Stack
- 코딩
- itertools
- 코테
- cte
- 프로그래머스
- python
Archives
- Today
- Total
ror_coding
[HackerRank] Type of Triangle 본문
728x90
삼각형이 되기 위한 세 변의 조건.
Question
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
Point
- 세 변의 길이가 같을 때 먼저,
- 한 변이 다른 두 변의 합보다 크거나 같을 때 삼각형이 아니기 때문에 예외 처리를 두 번째에,
- 이후 두 변이 같을 때 (이때, 세 변이 같은 케이스는 첫 번째때 리턴했기 때문에 문제 없음)
- 마지막 else 구문은 세 변의 길이가 모두 다를 때로 처리됨.
Code
SELECT
CASE
WHEN A=B AND B=C THEN 'Equilateral'
WHEN (A+B <= C) OR (B+C <= A) OR (C+A <= B) THEN 'Not A Triangle'
WHEN A=B OR A=C OR B=C THEN 'Isosceles'
ELSE 'Scalene'
END
FROM TRIANGLES
now me

728x90
'Coding Test > SQL' 카테고리의 다른 글
[LeetCode] 176. Second Highest Salary (0) | 2025.07.13 |
---|---|
[HackerRank] Top Earners (0) | 2025.06.14 |
[HackerRank] Symmetric Pairs (0) | 2025.06.14 |
[HackerRank] Binary Tree Nodes (0) | 2025.04.05 |
[HackerRank] Occupations (0) | 2025.04.05 |