Development/알고리즘
[ 백준 알고리즘 ] 4153번 직각삼각형 (JAVA/python)
Jin’s
2020. 8. 10. 10:23
반응형
안녕하세요 Jin's 입니다.
백준 알고리즘의 수학2 중 직각삼각형 ( 문제 번호 : 4153 )의 소스입니다.
Java와 Python 두가지 버전 소스입니다.
* 직사각형 공식 z² = x² + y²
1) JAVA
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(true){
ArrayList<Integer> list = new ArrayList<>();
int x = 0;
for(int i=0; i<3; i++){
x = scan.nextInt();
list.add(x);
}
if(x==0) break;
list.sort(Comparator.naturalOrder());
if(Math.pow(list.get(2), 2)== Math.pow(list.get(0), 2)+Math.pow(list.get(1), 2)){
System.out.println("right");
}else{
System.out.println("wrong");
}
}
scan.close();
}
}
2) PYTHON
while True:
t = sorted(list(map(int, input().split())))
if sum(t) == 0:
break
else:
if t[2] ** 2 == (t[1] ** 2 + t[0] ** 2):
print('right')
else:
print('wrong')
여러분도 한번 풀어보세요!
반응형