Today I've successfully solved another UVA problem called Car (11715) and I wanted to share my solution here it is.

Problem Description

Please follow the link to see full Problem Description.


The input le may contain multiple test cases. Each test case can be one of the

1 u v t

2 u v a

3 u a s

4 v a s

Input will be terminated by a single `0'.


For each case of input you have to print one line containing the case number and

If 1 u v t are given then print s and a

If 2 u v a are given then print s and t

If 3 u a s are given then print v and t

If 4 v a s are given then print u and t

Check the samples for more details. You can assume that the given cases will not evaluate to aninvalid situation. Use double for all calculations and output all oating point numbers to three decimalplaces.

Sample Input

1 10 5 2.0
1 5 10.0 2
2 10 11 2
3 5 1 6
4 5.0 -1 6

Sample Output

Case 1: 15.000 -2.500
Case 2: 15.000 2.500
Case 3: 5.250 0.500
Case 4: 6.083 1.083
Case 5: 6.083 1.083

Understanding the solution

  • Taking Input Until user input 0.
  • Import math for sqrt
  • casenumber convert to list and using map to split all number are taken as float
  • In here we have use the Physics Formula over here.
  • casepointnumber is use for print the case we have go though.
Note: You can use switch case too. By using switch case you need to break it every time. That's why i did with if else. With switch case runtime 0.025 and with if else runtime 0.010.

Please let me know if it helped ! and if you have any suggestion let me know. Thanks