spoj#INDIPROG. Indicator of progression
Indicator of progression
When dealing with a long task, computers often provide a progress indicator to help users
estimate how much longer they will have to wait. This is especially useful when copying a large
number of data files from one drive to another.
In the Institute of Computer Power Control (ICPC) are very concerned about their brand new
file copier, which they think will change forever the way people copy files. While this is a great
accomplishment for the engineers in ICPC, the lack of a progress indicator is threatening the
future of the project and the well being of most computer users around the world!
The Supremum Principal Director Manager of ICPC has called you personally to ensure you
are up for the task. The interface provided by the developing team of the file copier only gives
two integers M and N . M is the number of files that have already been copied, and N is
the total number of files to be copied. Using this information, you must write a module that
displays the progress indicator.
The indicator must be drawn as a string of exactly 20 characters. The first K of them must
be asterisks (“*”) and the rest must be hyphens (“-”). The number K must be chosen in such
a way that K/20 correctly approximates M/N ; this means that the distance between the two
mentioned fractions is minimum. If there is more than one possible value for K, the greatest
one must be chosen.
Also, for more precision, a number P without leading zeroes and followed by a percentage
sign (“%”) must be written on top of the described indicator. Since the goal is to represent
the finished percentage, the number P must be such that P/100 correctly approximates M/N ,
with the same policy as before. The finished percentage must be centered on top of the display.
This means that if possible, the same number of display characters (“*” or “-”) must be seen
to the left and to the right of the percentage; if this is not possible, exactly one extra character
must be seen to the left.
Input
The input contains several test cases. Each test case is described in a single line that contains
two integers M and N as explained above (0 ≤ M ≤ N ≤ 109 and N ≠ 0). These values are
separated by a single space. The last line of the input contains the number −1 twice separated
by a single space and should not be processed as a test case.
Output
For each test case output a single line with exactly 20 characters representing the mentioned
display.
Example
Input:
2 5
2 6
0 10
-1 -1
Output:
********-40%--------
*******--33%--------
---------0%---------