SP1285 CFRAC2 - Continuous Fractions Again
Description
A simple continuous fraction has the form:

where the ai’s are integer numbers.
The previous continuous fraction could be noted as \[a1, a2, . . . , an\]. It is not difficult to show that any rational number p / q , with integers p > q > 0, can be represented in a unique way by a simple continuous fraction with n terms, such that p / q = \[a1, a2, . . . , an−1, 1\], where n and the ai’s are positive natural numbers.
Now given a simple continuous fraction, your task is to calculate a rational number which the continuous fraction most corresponds to it.
Input Format
Input for each case will consist of several lines. The first line is two integer m and n,which describe a char martrix,then followed m lines,each line cantain n chars. The char martrix describe a continuous fraction The continuous fraction is described by the following rules:
2. Horizontal bars are formed by sequences of dashes `-'.
3. The width of each horizontal bar is exactly equal to the width of the denominator under it.
4. Blank characters should be printed using periods `.'
5. The number on a fraction numerator must be printed center justified. That is, the number of spaces at either side must be same, if possible; in other case, one more space must be added at the right side. The end of the input is indicated by a line containing 0 0.
Output Format
Output will consist of a series of cases, each one in a line corresponding to the input case. A line describing a case contains p and q, two integer numbers separated by a space, and you can assume that 10^20 > p > q > 0.