일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- level4
- counter
- 프로그래머스
- 조합
- Queue
- Level2
- Stack
- cte
- 코딩테스트
- sql
- lambda
- Growth hacking
- python
- 파이썬
- 코테
- hackerrank
- import re
- coding
- 코딩
- tableau
- mysql
- join
- AARRR
- 완전탐색
- itertools
- programmers
- time complexity
- collections
- lv4
- coding test
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' 카테고리의 다른 글
[HackerRank] Placements (1) | 2025.06.14 |
---|---|
[HackerRank] The Report (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 |