Algorithm

[백준] 4153번 직각삼각형 (JAVA)

KMSEOP 2020. 5. 22. 14:25
728x90

문제

과거 이집트인들은 각 변들의 길이가 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.util.Scanner;

public class no_4153 {

	public static void main(String[] args) {
		
		int side1, side2, side3;
		double result;
		
		Scanner sc = new Scanner(System.in);
		while(true) {
			side1 = sc.nextInt();
			side2 = sc.nextInt();
			side3 = sc.nextInt();
			
			if(side1 == 0 && side2 == 0 && side3 == 0) {
				break;
			}
			
			if(side1 > side2) {
				result = Math.pow(side1, 2) - Math.pow(side2, 2) - Math.pow(side3, 2);
			}else if(side2 > side3){
				result = Math.pow(side2, 2) - Math.pow(side1, 2) - Math.pow(side3, 2);
			}else {
				result = Math.pow(side3, 2) - Math.pow(side1, 2) - Math.pow(side2, 2);
			}
			if(result == 0) {
				System.out.println("right");
			}else {
				System.out.println("wrong");
			}
		}
	}
}

 

728x90