Woburn Challenge 1998

Episode 6: Return of the Plachta

Han Solo (who is a pilot), having handily beaten Three Thumbs Plachta at bowling is talking to some friends at a bar. Here, he recounts a tale of the legendary driver known only as "Forth-and-back" Plachta. He tells of a day when she was driving a bunch of students down in a foreign land known as the United States. Unsatisfied with the posted speed limit of 70mph, Ms. Plachta makes the calculations to prepare her van for the jump to hyperspace. Of course, everyone knows that this is a difficult task and some complicated calculations need to be made, including the adding of fractions. You will help her make the jump to light speed because, obviously, you want to live. All you have to do is add 2 fractions together and return the resulting fraction in reduced form.


4 numbers separated by spaces representing respectively numerator1, denominator1, numerator2, denominator2. Each of the input numbers will be in the range 0 ≤ numerator ≤ 32000 or 0 < denominator ≤ 32000. There will be 5 such inputs, ie. 5 sets of fractions to add.


Add the 2 fractions on each line together and return the reduced fraction (one line for each set). If the reduced fraction is a whole number, you should output it as a whole number and not as a fraction.

Sample Input

2 3 4 5 (ie. 2/3 + 4/5)
2 3 5 6 (ie. 2/3 + 5/6)
1 2 1 2 (ie. 1/2 + 1/2)
24000 1 24000 2
0 2 0 5

Sample Output

22 15 (ie. 22/15)
3 2 (ie. 3/2)

All Submissions
Best Solutions

Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008

Languages Allowed:

Comments (Search)

My program worked fine and passed all the sample input,but when I submit it says Your Output:"./a:_line_2:__5679_C..."
is this because my program is too slow?

Yes; the message says says "5679 CPU time limit exceeded."

why i get wrong
time error

That means your program is too slow.
Did you try extreme test cases on your computer?
(Remember that the numerator and denominator can go up to 32000)

Can someone look at my program and tell me whats wrong with it??

It calculates the samples properly??

why do you have semicolons after your if statements braces?

That in itself does not constitute a problem. Most of the time, an extra semicolon is simply an empty statement. The problem arises when they are placed after for loop headers, if statement conditions, etc.

I removed the semicolons now.., It still doesn't work..

well in that case, you should look at your algorithm.


I refer you here, because this is the best way to do this problem.

So my program isn't working because its taking too much time?? Is everything else fine??

Actually only your output format is wrong.
Look at your output, and the sample output, and the difference should be clear.

(the one that got 3/5)

I can't tell you because your submissions got accidentally deleted.

never mind - i found out what it was.

Euclidean algorithm to find the greatest common factor

how do you do the link thingy?

What do you think "BBCode/Smilies" is for...

How do you guys get such fast run times?

What do you mean? What runtime did you get?