Code Wars V
     

Program / Task Name:

   The Ant and the Candy

Level:

 

 Intermediate

Point Value:

 

 9

 

Task Description

There is an ant and a candy on the surface of a rectangular box. The ant cannot fly. It can only walk on the surface of the box to the candy. Please write a program that calculates the distance of the shortest path from the ant to the candy. The coordinates of the eight corners of the rectangular box are shown in the figure below.

The initial position of the ant can be on the top or one of the sides of the box (including the corners).  It cannot be on the bottom.  The candy is always on the top of the box.  The candy cannot be on the edges or corners of the box (or it will fall off).

Program Input

The input to the program is provided in prob10.in.  Each input line consists of six numbers separated by a blank. First three numbers are the coordinates representing the position of the ant while the remaining three numbers are the coordinates representing the position of the candy. You may assume these coordinates are on the surface of the rectangular box. For example, the first line of the sample input means that the ant is at (3,1,3) and the candy is at (3,3,3). Assume that the data given is always valid.

Sample Input:

3 1 3 3 3 3
2.25 0 2 2.5 2 3
0 0 0 5 4 3.0
0 4 3 5 0.0 3
5 0 3 5 4.00 3

Program Output

A real number represents the distance of the shortest path from the ant to the candy. On the screen, print the distance accurate to two digits to the right of the decimal point in the following format.

Sample Output:

Shortest distance = 2.00 units
Shortest distance = 3.01 units
Shortest distance = 8.60 units
Shortest distance = 6.40 units
Shortest distance = 4.00 units

 

hp Code Wars
Hello -- Dominos?...
   
  (c) 2004 Hewlett-Packard Company