본문 바로가기

알고리즘 풀이(JAVA)/백준

[백준] 문제번호 4153(직각삼각형)(브론즈 3)(java)

<문제 4153 - 직각삼각형>

[문제]

[답안]

// 피타고라스의 정리를 이용하여 풀이

import java.util.Scanner;

public class Main {
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        while (true){
            int a = sc.nextInt(); // a의 숫자
            int b = sc.nextInt(); // b의 숫자
            int c = sc.nextInt(); // c의 숫자

            if (a== 0 && b == 0 && c == 0){
                break;
            }
            if (Math.pow(c,2) == Math.pow(a,2) + Math.pow(b,2)){
                System.out.println("right");
            } else if (Math.pow(b,2) == Math.pow(a,2) + Math.pow(c,2)) {
                System.out.println("right");
            } else if (Math.pow(a,2) == Math.pow(b,2) + Math.pow(c,2)) {
                System.out.println("right");
            }else {
                System.out.println("wrong");
            }
        }
    }
}

백준

https://www.acmicpc.net/problem/4153

 

4153번: 직각삼각형

입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다.

www.acmicpc.net