I'm working on a Rational number class in c++. The Rational number is defined by two int (numerator and denominator). I would like to display it properly as digit number. for now, I determine if the number is an "illimited" or a limited digit rational number.
Here is a little pseudo code to illustrate:
define print_rational(num, denom):
if(isUnlimited(num, denom):
?
else:
//"limited" rational, no problem for them
I would like to display illimited numbers like this : print one time the repetitives digits, then "..." (Example : 1/3 -> 0.3..., 1/11 -> 0.09...)
So, is there an algorithm to find the block of digit who will be repeat in a rational number ?
Convert your result into string and then apply Longest repeated substring problem to it.