[BOJ 4153] 직각삼각형
Baekjoon Online Judge 4153(Java 11)
[직각삼각형] 문제 풀이
[BOJ 4153] 직각삼각형
시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 124399 | 62273 | 55468 | 49.580% |
문제
- 과거 이집트인들은 각 변들의 길이가 3, 4, 5인 삼각형이 직각 삼각형인것을 알아냈다. 주어진 세변의 길이로 삼각형이 직각인지 아닌지 구분하시오.
입력
- 입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다.
출력
- 각 입력에 대해 직각 삼각형이 맞다면 “right”, 아니라면 “wrong”을 출력한다.
예제
1
2
3
4
5
// 입력
6 8 10
25 52 60
5 12 13
0 0 0
1
2
3
4
// 출력
right
wrong
right
출처
- Contest > Waterloo’s local Programming Contests > 2 October, 2010 A번
- 문제를 번역한 사람: josephwon0310
- 잘못된 데이터를 찾은 사람: occidere
알고리즘 분류
제출
내 제출
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.*;
public class Main {
public static void solution() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while (true) {
StringTokenizer st = new StringTokenizer(br.readLine()," ");
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int z = Integer.parseInt(st.nextToken());
// 0 0 0 을 입력받으면 종료
if (x == 0 && y == 0 && z == 0) break;
if ((x * x + y * y) == z * z) {
System.out.println("right");
} else if (x * x == (y * y + z * z)) {
System.out.println("right");
} else if (y * y == (z * z + x * x)) {
System.out.println("right");
} else {
System.out.println("wrong");
}
}
bw.flush();
bw.close();
br.close();
}
public static void main(String[] args) throws IOException {
solution();
}
}
런타임 | 메모리 |
---|---|
100 ms | 14192 KB |
Reference
This post is licensed under CC BY 4.0 by the author.