Triangle(https://www.codechef.com/CBST2021/problems/TRANG)

Practice

Author: noob_tech
Tester: noob_tech
Editorialist: noob_tech

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

Math .

PROBLEM:

CodeMaster has given three sides of a triangle i.e(a,b,c). CodeMAster has task to find Square of the greatest side is equal to sum of square of remaining sides.

If Square of Greatest side is equal to sum of square of remaining sides then print RIGHT ANGLE TRIANGLE else Print NOT.

QUICK EXPLANATION

We will use formula c^2=a^2+b^2 where c is greater side of triangle. if c^2=a^2+b^2 then print RIGHT ANGLE TRIANGLE else NOT.

EXPLANATION:

We are given three side of a triangle i.e(a,b,c). Consider the three sides are 3,4,5.
Here a=3,b=4 and c=5. we have to check whether the square of the greater side(Here greatest side is c) is equal to sum of square of remaining sides(Here remaining side is a and b).
Here,in this particular eaxmple we have to check whether c^2=a^2+b^2 or Not.
Here, 5^2=3^2+4^2, So the ans should be RIGHT ANGLE TRIANGLE.

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
long long n=3;
int main()
{
int t;
cin>>t;
while(t- -)
{
long long a[n]={0};
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(a,a+n);
long long d=a[2]*a[2];
long long e=(a[1]*a[1])+(a[0]*a[0]);
if(d==e)
{
cout<<“RIGHT ANGLE TRIANGLE”<<endl;
}
else
{
cout<<“NOT”<<endl;
}
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
long long n=3;
int main()
{
int t;
cin>>t;
while(t- -)
{
long long a[n]={0};
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(a,a+n);
long long d=a[2]*a[2];
long long e=(a[1]*a[1])+(a[0]*a[0]);
if(d==e)
{
cout<<“RIGHT ANGLE TRIANGLE”<<endl;
}
else
{
cout<<“NOT”<<endl;
}
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
long long n=3;
int main()
{
int t;
cin>>t;
while(t- -)
{
long long a[n]={0};
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(a,a+n);
long long d=a[2]*a[2];
long long e=(a[1]*a[1])+(a[0]*a[0]);
if(d==e)
{
cout<<“RIGHT ANGLE TRIANGLE”<<endl;
}
else
{
cout<<“NOT”<<endl;
}
}
return 0;
}