코테용 문제풀이/백준

직각삼각형 풀이

doctscoder 2023. 1. 9. 09:39

문제 링크: https://www.acmicpc.net/problem/4153

백준 기하 1 3단계 - 4153번 직각삼각형을 풀어보았다.

 

풀이: 세 변을 입력받고, 피타고라스 정리를 이용해 직각삼각형인지를 알아본다.

 

C++

#include <iostream>

using namespace std;

int main()
{
  int a,b,c;
  while(true)
  {
  	cin>>a>>b>>c;
    if(a==0&&b==0&&c==0) break;
    if(a*a==b*b+c*c) cout<<"right\n";
    else if(b*b==a*a+c*c) cout<<"right\n";
    else if(c*c==b*b+a*a) cout<<"right\n";
    else cout<<"wrong\n";
  }
}

Python

while 1:
	a,b,c=map(int,input().split())
	if a==0 and b==0 and c==0: break
	if a*a==b*b+c*c or b*b==a*a+c*c or c*c==a*a+b*b: print("right") # 직각삼각형이면
	else: print("wrong")

Java