String Pattern Matching algo
- From: "116Rohan@xxxxxxxxx" <116Rohan@xxxxxxxxx>
- Date: 29 Apr 2006 13:52:28 -0700
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.
.
- Follow-Ups:
- Re: String Pattern Matching algo
- From: Barry Schwarz
- Re: String Pattern Matching algo
- From: Rod Pemberton
- Re: String Pattern Matching algo
- From: Martin Ambuhl
- Re: String Pattern Matching algo
- From: websnarf
- Re: String Pattern Matching algo
- From: Flash Gordon
- Re: String Pattern Matching algo
- From: 116Rohan@xxxxxxxxx
- Re: String Pattern Matching algo
- Prev by Date: Re: Boost process and C
- Next by Date: Re: enumeration variables
- Previous by thread: help me learn C
- Next by thread: Re: String Pattern Matching algo
- Index(es):
Relevant Pages
|
|