직각삼각형 조건 공식
-> 피타고라스 사용
a^2 + b^2 = C^2 가
true일 때 right
false일 때 wrong 출력
틀렸습니다
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
while(a != 0 && b != 0 && c != 0){
if (a*a + b*b == c*c)
printf("right\n");
else
printf("wrong\n");
cin >> a >> b >> c;
}
return 0;
}
while문의 조건을 쉽고 명확히 하기 위해 if문에 break를 사용 (틀렸습니다)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
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)
printf("right\n");
else
printf("wrong\n");
}
return 0;
}
빗변을 정확히 정하지 않아 계속 틀렸습니다.
이를 고치기 위해 배열로 입력 받고 정렬하는 코드로 수정하였습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
a.resize(3);
while(true){
cin >> a[0] >> a[1] >> a[2];
if(a[0] == 0 && a[1] == 0 && a[2] == 0)
break;
sort(a.begin(), a.end());
if (a[0]*a[0] + a[1]*a[1] == a[2]*a[2])
printf("right\n");
else
printf("wrong\n");
}
return 0;
}
드디어 성공했습니다. 너무 오랜만에 풀어서 시행착오가 좀 있었습니다,,,