Home > Back-end > 7-9 triangle judgment (15 points)
7-9 triangle judgment (15 points)
Time:10-21
A given plane coordinates of any three points (x1, y1), (x2, y2), (x3, y3? ), check whether they constitute a triangle,
Input format: Input sequence is given in a line of six? [100100] within the scope of digital, namely three point coordinates x1, y1? , x2? , y2? , the x3? , y3? ,
The output format: If the three points can't form a triangle, the output in one line "Impossible". If you can, then output in one line of the triangle pupil, format is "L=c, A=area", the output to 2 decimal places,
Input the sample 1: 4 5 6 7 8 9 The output sample 1: L=10.13, 3.00 A=Enter the sample 2: 4, 6, 8 12 12 18 The output sample 2: Impossible Thinking: area was calculated by the vector of cross-product Code: #include #include
Int main (int arg c, const char * argv []) { Double x1, x2, x3, y1, y2, y3. Double l, a; The scanf (" % lf lf lf lf lf % % % % % lf ", & amp; X1, & amp; Y1, & amp; X2, & amp; Y2, & amp; The x3, & amp; Y3); If ((x1 - x2) * (y2, y3)==(x2, x3) * (y1, y2)) { Printf (" Impossible "); } The else { (l=SQRT (pow (x1, x2), 2) + pow ((y1, y2), 2)) + SQRT (pow ((x1 - x3), 2) + pow ((y1, y3), 2)) + SQRT (pow ((x2, x3), 2) + pow ((y2 - y3), 2)); A=fabs ((x1, x2) * (y3 - y2) - (x3 - x2) * (y1, y2))/2; Printf (" lf L=%. 2, A=%. 2 lf ", L, A); } return 0; } The code has been can't pass the final test, the sample is correct, don't know what a great god can help me
CodePudding user response:
If ((x1 - x2) * (y2, y3)==(x2, x3) * (y1, y2)) so is wrong, such as Floating point Numbers to use such as Fabs (their) & lt; 1 e - 12;
CodePudding user response:
Logic seems no problem Printf end to add \ n?
CodePudding user response:
At 3 o 'clock not collinear can form a triangle, there is no need to calculate the distance
CodePudding user response:
Long knowledge, but after I get rid of or can't, I with Helen before the formula to calculate area, can be through, so I don't think this judgment equal place should be the key problem
CodePudding user response:
Fabs is o (y2 - y1/x2 - x1) and fabs (y3 - y1/x3 - x1) are equal