String Pattern Matching algo



I came across a question in one of the Computing olympiad regarding
string pattern matching.

Write a program that will accept a fraction of the form N/D, where N is
the numerator and D is the denominator, that prints out the decimal
representation. If the decimal representation has a repeating sequence
of digits, it should be indicated by enclosing it in brackets. For
example, 1/3 = .33333333...is denoted as .(3), and 41/333 =
..123123123...is denoted as .(123).

Typical conversions are:

1/3 = .(3)
22/5 = 4.4
1/7 = .(142857)
3/8 = .375
45/56 = .803(571428)

Now I could not think how do I even start writing a logic for creating
a pattern.
Then I thought that maybe I should start comparing characters from the
right rather than the left.
But these two examples even negate that theory;

1/7 gives me ---> 0.1428571428571428571428571429 on a 16bit machine

45/56 gives me ---> 0.8035714285714285714285714286

I was trying to eliminate the last number as it rounds off, and so I
can start creating combinations from right to left. But nothing seems
to be working.

Any hints/suggestions will be appreciated.

.



Relevant Pages

  • Re: String Pattern Matching algo
    ... string pattern matching. ... the numerator and D is the denominator, ... If the decimal representation has a repeating sequence ... Then you just have to watch out for when you start repeating yourself... ...
    (comp.lang.c)
  • Re: String Pattern Matching algo
    ... string pattern matching. ... Write a program that will accept a fraction of the form N/D, ... and note the repeating pattern like you did by hand. ... *after* the last significant digit of the numerator is consumed by the ...
    (comp.lang.c)
  • Re: String Pattern Matching algo
    ... string pattern matching. ... Write a program that will accept a fraction of the form N/D, ... decimals to the form N/D. ... the conversion N and D, ...
    (comp.lang.c)