Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2014. november 30.

November 30, 2014 10:30 AM – November 30, 2014 3:30 PM

Grachten

Damn! I did not only oversleep (and today is the contest day!) but also got stuck somewhere in Delft on my way from the hotel to the contest site. Everywhere around me are grachten, these city-canals, which are part of many cities in the Netherlands. I am in a bit of hurry because the NWERC (Northwestern European Regional Contest) starts in a few minutes.

To make matters even worse, some bridges in Delft are closed due to a cycling race through the city. Thus, I decided to jump over some of the grachten instead of searching for open bridges.

Everyone knows that computer scientists like me are good at algorithms but not very good athletes. Besides, I am a bit faint-hearted and don't want to get wet. So I need your help to calculate the distance I have to jump over a gracht.

Luckily, I did attend the excursion in Delft city center yesterday, where I learned that all paving stones in Delft are squares and have the same size. This way, I can do some measurements on my side of the gracht (my units are paving stones):


Figure 1: Illustration of first sample input.

I walked from point C to point D via points A and B, while counting the paving stones.

Points A and C are always on the edge of the gracht. Points B and D have the same distance to the gracht. The target point T is always on the edge of the other side of the canal; it is the intersection point of the line through B and A, and the line through D and C. The angle between AT and AC is 90 degrees, and the two edges of the canal are parallel lines.

Please calculate the distance between A and T (the necessary jump distance) for me.

Input Specification

For each test case, the input consists of one line containing three positive integers that specify the distances between A and B, A and C, and B and D.

You may safely assume that no distance is larger than 1000 and that the distance between B and D is larger than the distance between A and C.

Output Specification

For each test case, print one line of output: the distance between A and T as a reduced fraction (i.e., remove all common factors of the numerator and the denominator).

Sample Input

  1. 5 3 7
  2. 5 3 8
  3. 1 2 3
  4. 23 42 47
  5. 500 500 1000
  6. 1 1 1000
download as text file

Output for Sample Input

  1. 15/4
  2. 3/1
  3. 2/1
  4. 966/5
  5. 500/1
  6. 1/999
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019