반응형
https://www.acmicpc.net/problem/9723
9723번: Right Triangle
For each test case, the output contains a line in the format Case #x: M, where x is the case number (starting from 1) and M is “YES” when the given triangle is a right triangle or “NO” otherwise. Note that the quotes are not required to be outputte
www.acmicpc.net
간단한 구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
test case t, 세 변 a를 선언 후 입력받습니다. 그리고 정답을 출력할 변수 ans를 선언합니다.
📔 풀이과정
세 변을 a에 입력받았으므로 오름차순으로 정렬합니다. a[2]^2 = a[0]^2 +a[1]^2면 ans = YES이며 아닌 경우 NO를 저장합니다.
📔 정답출력
형식에 맞게 출력합니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int t, a[3];
string ans;
int main(){
cin >> t;
for(int i = 1; i <= t; i++){
cin >> a[0] >> a[1] >> a[2];
ans = "YES";
sort(a, a + 3);
if (a[2] * a[2] != a[0] * a[0] + a[1] * a[1]) ans = "NO";
cout << "Case #" << i << ": " << ans << '\n';
}
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(Rust) - 백준(BOJ) 25286 : 11월 11일 (2) | 2022.08.17 |
---|---|
(Rust) - 백준(BOJ) 9297 : Reducing Improper Fractions (0) | 2022.08.16 |
(C++) - 백준(BOJ) 22380 : 割り勘 (0) | 2022.08.12 |
(C++) - 백준(BOJ) 9838 : XMAS (0) | 2022.08.11 |
(C++) - 백준(BOJ) 9622 : Cabin Baggage (0) | 2022.08.10 |