PS/백준
[백준] 4153번: 직각삼각형_Java
codeStudy123
2022. 4. 19. 21:48
제목: 직각삼각형
브론즈3
문제

과거 이집트인들은 각 변들의 길이가 3, 4, 5인 삼각형이 직각 삼각형인것을 알아냈다. 주어진 세변의 길이로 삼각형이 직각인지 아닌지 구분하시오.
입력
입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다.
출력
각 입력에 대해 직각 삼각형이 맞다면 "right", 아니라면 "wrong"을 출력한다.
예제 입력 1 복사
6 8 10
25 52 60
5 12 13
0 0 0
예제 출력 1 복사
right
wrong
right
🔑 코드
import java.io.*;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int line = Integer.parseInt(st.nextToken());
if (x == 0 && y == 0 && line == 0)
break;
if (line * line == (x * x) + (y * y)) {
sb.append("right");
} else if (x * x == (y * y) + (line * line)) {
sb.append("right");
} else if (y * y == (x * x) + (line * line)) {
sb.append("right");
} else {
sb.append("wrong");
}
System.out.println(sb);
}
}
}
알고리즘 분류
https://www.acmicpc.net/problem/4153
4153번: 직각삼각형
입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다.
www.acmicpc.net