F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Continued Fraction

Time 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
LR RL
 

Sample Output
1 0 + ----- 1 1 + - 2 1 1 + - 2
 

Author
Dumbear@WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-05 00:10:16, Gzip enabled