编程介的小学生 2017-04-27 07:46 采纳率: 20.5%
浏览 837
已采纳

Mixed Numbers

Description

A mixed fraction is defined recursively as follows:

A real value is a simple mixed fraction. For simplicity, we only consider one digit positive integer numbers greater than zero (digits 1 ... 9).
If a is a real value (which is again assumed as an integer between 1 and 9), and b and c are two mixed fractions,
b

a- is a mixed fraction which is equal to a + b/c

c

Sum of a number of mixed fractions is also a mixed fraction.

One can draw a view of a mixed fraction using ASCII characters as described below:

A simple mixed fraction can be drawn using one digit character.
b

The mixed fraction a- will be drawn using a digit showing a , and a horizontal line that starts

                 c

immediately after the letter representing a (in the same row) using '-' characters. b and c are drawn recursively above and below the horizontal line respectively, such that their figures do not exceed the line from left nor right.
Sum of mixed fractions is represented by drawing the mixed fractions and inserting a '+' character between each consequence pair such that the '+' character and the first character of the next and the previous mixed fractions make a horizontal line.

We want you to write a program to calculate the value of a mixed fraction from its figure.
Input

Some 90 degree clockwise rotated figures of a number of mixed fractions are given in the input file. In the first line of each rotated mixed fraction n < 300 and m < 15000 , the length and the width of the figure, are written. In the next m lines the figure i s described ('-' is replaced with '|'). Note that each line will consists of exactly n characters so any number of spaces may be used in the shape, but anyway, the shape of the figure satisfies description explained above.
The input ends with a line containing two zeroes.
Output

For each test case write its value in a separate line. Your answer must be rounded to two digits after decimal point and the output must contain exactly two digits after the decimal point.
Sample Input

8 6
1

2 | 2
4|2| 4|3
|


  • 1
    0 0 Sample Output

3.10

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-05-11 15:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler