|
||||||||||
Continued FractionTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 507 Accepted Submission(s): 157 Problem Description Dumbear loves numbers very much. One day Dumbear found that each number can be expressed as a continued fraction. See below. Formally, we say a number k can be expressed as a continued faction if where a0, a1, ¡, an are positive integers except that a0 maybe be 0 and an cannot be 1. Dumbear also found a sequence which looks like the Farey sequence. Initially the sequenceand if we insert an elementbetween all the two adjacent element,in Di, then we get a sequence Di+1. So you can seeandAssume initially you are on the elementin D0, and if now you are on the element k in Di, then if you go left(¡®L¡¯)(or right(¡®R¡¯)) you will be on the left(or right) element of k in Di+1. So a sequence composed of ¡®L¡¯ and ¡®R¡¯ denotes a number. Such as ¡®RL¡¯ denotes the number Now give you a sequence composed of ¡®L¡¯ and ¡®R¡¯, you should print the continued fraction form of the number. You should use ¡®-¡® to show the vinculum(the horizontal line), you should print one space both in front and back of ¡®+¡¯, and all parts up or down the vinculum should be right aligned. You should not print unnecessary space, ¡®-¡® or other character. See details in sample. Input There are several test cases in the input. For each test case, there is a single line contains only a sequence composed of ¡®L¡¯ and ¡®R¡¯. The length of the sequence will not exceed 10000. The input terminates by end of file marker. Output For each test case, output the continued fraction form of the number which the input sequence denotes. The total amount of output will not exceed 4MB. Sample Input
Sample Output
Author Dumbear@WHU Source | ||||||||||
|