
<IntegerPart> < ‘.’ > <Non-ReaptingPart> < ‘(‘ > <ReaptingPart> < ‘)’ >.
5 / 1 as ‘5’
12 / 100 as ‘0.12’
11 / 6 as ‘1.8(3)’
1 / 3 as 0.(3).
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains two space-separated strings ‘S’ and ‘T’ denoting the given two strings.
For each test case, print 1 if both strings represent the same number else print 0.
The output of each test case will be printed in a separate line.
You do not need to input or print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= length of <IntegerPart> <= 4
0 <= length of <Non-ReaptingPart>, <RepeatingPart> <= 4
<IntegerPart> doesn’t contain leading zeros, except for 0 itself.
Where <IntegerPart>, <Non-ReaptingPart>, and <ReaptingPart> are the part of the given string ‘S’ and ‘T’ according to the format in the problem.
The idea is to expand both given strings to a fixed length and compare both numbers. A key point to observe here is that we cannot compare strings directly, we have to convert strings into a double value. For example, strings ‘1.0’ and ‘1’ are different but have the same value. So after expanding strings, we compare their double value.
This function will take one parameter:
As we know that all rational numbers can be represented in the form of ‘P’ / ‘Q’. Where ‘P’ and ‘Q’ are some integers and ‘Q’ can not be 0. So we will find the corresponding ‘P’ / ‘Q’ for both the given strings and compare them. To find fractional parts for repeating parts, we will use infinite G.P. sum.
For example, consider ‘0.(3)’ i.e. 0.33333…..
This can be written as sum: 0 + 0.3 + 0.03 + 0.003+ 0.0003 + …..
= 0 + 0.3 * (1 + 0.1 + 0.01+ 0.001 + 0.0001 + …..)
Which is an infinite geometric series whose sum is equal to 0.3* (1 / (1 - 0.1 ).
This function will take one parameter: