Chef and The Right Triangles

Description:

The Chef is given a list of N triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane. His job is to figure out how many of the given triangles are right triangles. A right triangle is a triangle in which one angle is a 90 degree angle. The vertices of the triangles have integer coordinates and all the triangles given are valid( three points aren't colinear ). Input The first line of the input contains an integer N denoting the number of triangles. Each of the following N lines contain six space separated integers x1 y1 x2 y2 x3 y3 where (x1, y1), (x2, y2) and (x3, y3) are the vertices of a triangle. Output Output one integer, the number of right triangles among the given triangles. Constraints 1 N 100000 (105) 0 x1, y1, x2, y2, x3, y3 20 Test Case 1 Input (stdin) 5 0 5 19 5 0 0 17 19 12 16 19 0 5 14 6 13 8 7 0 4 0 14 3 14 0 2 0 14 9 2 Expected Output 3 Test Case 2 Input (stdin) 3 0 2 2 4 0 4 5 3 5 0 0 0 2 4 4 2 0 4 Expected Output 2

Program :

import java.util.*;

public class TestClass{

public static void main(String[] args) {

Scanner s=new Scanner(System.in);

int t=s.nextInt();

int out=0;

while(t>0){

int x1=s.nextInt();

int y1=s.nextInt();

int x2=s.nextInt();

int y2=s.nextInt();

int x3=s.nextInt();

int y3=s.nextInt();

int a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);

int b=(x3-x1)*(x3-x1)+(y3-y1)*(y3-y1);

int c=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);

if(a>b&&a>c){

if(a==b+c){

out++;

}

}

else if(b>a&&b>c){

if(b==a+c){

out++;

}

}

else if(c>a&&c>b){

if(c==a+b){

out++;

}

}

t--;

}

System.out.println(out);

}

}