I have got a problem to check if three points form a triangle or not. If it forms a triangle the program should print the square of maximum length of the three sides of the triangle. If not the program will print "Coolinear".
Anyways here is a sample of what I have tried:
#include <iostream>
#include <cmath>
using namespace std;
int main () {
double x1,y1,x2,y2,x3,y3;
double area;
double s1,s2,s3;
cin >> x1 >> y1;
cin >> x2 >> y2;
cin >> x3 >> y3;
area = 0.5*abs(((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)));
s1 = ((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2));
s2 = ((x2-x3)*(x2-x3))+((y2-y3)*(y2-y3));
s3 = ((x1-x3)*(x1-x3))+((y1-y3)*(y1-y3));
if (area!=0){
if (s1 >= s2 && s1 >= s3)
cout<<s1<<endl;
if (s2 >= s1 && s2 >= s3)
cout<<s2<<endl;
if (s3 >= s1 && s3 >= s2)
cout <<s3<<endl;
}
else
cout <<"Coollinear";
return 0;
}
I submitted this code on codeforces website as it is my last problem on a contest. It gives me wrong answer at test 9, What else should I use? and Why is my answer wrong?
Anyways Here is the text of the problem:
Like all problem solvers, Meiko loves eating crepe! As we all know, crepe usually served in a triangular shape. Now Meiko wants to know how large can a crepe side be! So he tries to draw a triangle on a plane using three points and calculate the maximum length of the three sides of the triangle. But sometimes he falls asleep as he has been busy with the team preparing the training problems! As a result, the three points he uses may not form a triangle that could represent a piece of crepe! A triangle can represent a piece of crepe only if it has a positive area. So you are here to help Meiko! Given the coordinates Meiko used, determine whether they form a triangle that could represent a piece of crepe or not.
Input Three integer coordinates (X,Y) that represent the three points Meiko used. Each point on a separate line. (-10^9<=X,Y<=10^9)
Output If the points form a triangle that can represent a piece of crepe, print the square of the maximum length of the three sides of the triangle. Otherwise print "Collinear" without quotes.