🔗 백준 4153 직각삼각형 https://www.acmicpc.net/problem/4153
**문제 **
과거 이집트인들은 각 변들의 길이가 3, 4, 5인 삼각형이 직각 삼각형인것을 알아냈다. 주어진 세변의 길이로 삼각형이 직각인지 아닌지 구분하시오.
입력
입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다.
출력
각 입력에 대해 직각 삼각형이 맞다면 “right”, 아니라면 “wrong”을 출력한다.
풀이
직각 삼각형은 z² = x² + y² 인데 이 문제에선 가장 긴 변이 입력받은 세개의 수 중 어떤 변인지 모른다.
그렇기에 나는 세개의 수가 각각 대각선인 조건을 3개를 만들었고 그 조건이 맞지 않는다면 “wrong”, 아니면 “true”를 출력시켜줬다.
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
import java.io.*;
import java.util.StringTokenizer;
public 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());
            double x = Integer.parseInt(st.nextToken());
            double y = Integer.parseInt(st.nextToken());
            double z = Integer.parseInt(st.nextToken());
            if (x == 0 && y == 0 && z == 0) break;
            if (Math.pow(x, 2) + Math.pow(y, 2) != Math.pow(z, 2)
             && Math.pow(y, 2) + Math.pow(z, 2) != Math.pow(x, 2)
             && Math.pow(z, 2) + Math.pow(x, 2) != Math.pow(y, 2)) {
                System.out.println("wrong");
            }
            else System.out.println("right");
        }
    }
}
