Last active
December 24, 2015 22:59
-
-
Save ylogx/6876742 to your computer and use it in GitHub Desktop.
P2 - Pythagorean Math Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* foobar - Shubham Chaudhary | |
* Nitul Datt | |
Pythagorean Math TestPythagoras is teaching mathematics to a class of N students. He wants to test if his students understood his new theorem. He gives his students the length of the sides of a triangle and they have to tell him if it is a right triangle.InputFirst line an integer N, the number of students. 0<N<=50Next N lines each containing 3 integers a, b and c which are the length of the sides of the triangle. 0<a,b,c. (DO NOT PRINT ANY PROMPT MESSAGE TO READ THE INPUT.)OutputIf the given triangle is right angled print "RIGHT TRIANGLE" in a single line. If the given triangle is not right angled print "NOT RIGHT TRIANGLE" in a single line. (DO NOT PRINT ANY MESSAGE OTHER THAN THE SPECIFIED OUTPUT.)Sample input23 5 43 2 1Sample outputRIGHT TRIANGLENOT RIGHT TRIANGLE | |
*/ | |
#include <stdio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
int fastread() | |
{ | |
unsigned int input; | |
char c=0; | |
while (c<33){ | |
c=getchar_unlocked(); | |
//printf("\nWHILE: c is %c",c); | |
} | |
input=0; | |
while (c>33) | |
{ | |
//printf("\nWHILE 2 : c is %c",c); | |
input=input*10+c-'0'; | |
//printf("\n%d * 10 + %d - %d",input,c,'0'); | |
c=getchar_unlocked(); | |
} | |
//printf("\nInput is : %d",input); | |
return input; | |
} | |
int main(){ | |
//foobar | |
int n; | |
n=fastread();//scanf("%d",&m); | |
int i; | |
for(i=0;i<n;i++){ | |
//~ int a,b,c; | |
int a[3]; | |
a[0]=fastread(); | |
a[1]=fastread(); | |
a[2]=fastread(); | |
//~ a=fastread(); | |
//~ b=fastread(); | |
//~ c=fastread(); | |
//~ int max=(a>b&&a>c? a : b>c?b:c); | |
//~ int pa=pow(fastread(),2); | |
//~ int pb=pow(fastread(),2); | |
//~ int pc=pow(fastread(),2); | |
//int max; | |
int index; | |
if(a[0]>a[1] && a[0]>a[2]){ | |
//max=a[0]; | |
index=0; | |
}else if(a[1]>a[2]){ | |
//max=a[1]; | |
index=1; | |
}else{ | |
//max=a[2]; | |
index=2; | |
} | |
//~ if(pa==pb+pc || pc==pb+pa || pb==pc+pa){ | |
//(pow(a,2)==(pow(b,2)+pow(c,2))) || (pow(b,2)==(pow(a,2)+pow(c,2))) || (pow(c,2)==(pow(b,2)+pow(a,2)))){ | |
if(pow(a[index],2) == pow(a[(index+1)%3],2) + pow(a[(index+2)%3],2)){ | |
printf("RIGHT TRIANGLE\n"); | |
}else{ | |
printf("NOT RIGHT TRIANGLE\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment