Test instructions roughly, give the value of two (both positive) values in the right triangle A,b,c (c is the hypotenuse) and evaluate to the edge of-1. For example, 3 4-1, is to seek the length of C, input 0 0 0 End of the table, the output format as follows bold part, I myself measured the results are correct, I do not know why always WA, ask the big God pointing!
Mathematics can is so and easy to have a computer. Consider the following example. You probably know this in a right-angled triangle, the length of the three sides A, B, C (where C is the longest side, Cal led the hypotenuse) satisfy the relation a*a+b*b=c*c. This is the called Pythagora ' s law.
Here we consider the problem of computing the length of the third side, if both are given.
Input
The input contains the descriptions of several triangles. Each description consists of a line containing three integers a, B and C, giving the lengths of the respective sides of a Right-angled triangle. Exactly one of the three numbers is equal to-1 (the ' unknown ' side), the others is positive (the ' given ' sides).
A description has a=b=c=0 terminates the input.
Output
For each triangle description in the input, first output the number of the triangle, as shown in the sample output. Then print "impossible." If there is no right-angled triangle, which has the ' given ' side lengths. Otherwise output the length of the ' unknown ' side in the format "s = L", where S is the name of the unknown side (a, B or c), and L are its length. L must is printed exact to three digits to the "right" of the decimal point.
Print a blank line after each test case.
Sample Input
3 4-1
-1 2 7
5-1 3
0 0 0
Sample Output
Triangle #1
c = 5.000
Triangle #2
A = 6.708
Triangle #3
Impossible.
My Code
Import Java.text.DecimalFormat;
Import Java.util.Scanner;
public class Geometry1241 {
Static Double A, B, C, result;
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner sc = new Scanner (system.in);
int temp = 1;
String No = "impossible.";
DecimalFormat df = new DecimalFormat ("#.000");
while (Sc.hasnext ()) {
A = Sc.nextint ();
b = Sc.nextint ();
c = Sc.nextint ();
if (A = = b && b = = c && c = = 0)
Break
if (A = =-1) {
result = c * C-b * b;
If (Result <= 0 | | c <= 0 | | b <= 0) {
System.out.println ("Triangle #" + temp);
System.out.println (No);
Continue
} else {
A = MATH.SQRT (result);
System.out.println ("Triangle #" + temp);
System.out.println ("a =" + Df.format (a));
}
}
if (b = =-1) {
result = c * c-a * A;
If (Result <= 0 | | c <= 0 | | A <= 0) {
System.out.println ("Triangle #" + temp);
System.out.println (No);
Continue
} else {
b = math.sqrt (result);
System.out.println ("Triangle #" + temp);
System.out.println ("b =" + Df.format (b));
}
}
if (c = =-1) {
if (a <= 0 | | b <= 0) {
System.out.println ("Triangle #" + temp);
System.out.println (No);
}
result = A * a + b * b;
c = math.sqrt (result);
System.out.println ("Triangle #" + temp);
System.out.println ("c =" + Df.format (c));
}
temp++;
System.out.println ();
}
}
}
To help a very simple ACM problem Java code on their own computer test is correct, but the submission is always wrong answer first thank you