332  Rational Numbers from Repeating Fractions
Moderator: Board moderators

 New poster
 Posts: 7
 Joined: Wed Dec 12, 2001 2:00 am
 Location: Bangladesh

 New poster
 Posts: 7
 Joined: Wed Dec 12, 2001 2:00 am
 Location: Bangladesh
Getting WA too...
I take care about cases where j == 0, but still got WA.
For:
0 0.5
My answer is 1/2
For:
0 0.35
My answer is 7/20
Can't get what's wrong...
BTW, should I compute the GCD between the denumerator and the numerator more than once? I think that the GCD will reduce it the most possible...
For:
0 0.5
My answer is 1/2
For:
0 0.35
My answer is 7/20
Can't get what's wrong...
BTW, should I compute the GCD between the denumerator and the numerator more than once? I think that the GCD will reduce it the most possible...

 Experienced poster
 Posts: 167
 Joined: Fri Oct 19, 2001 2:00 am
 Location: Saint Petersburg, Russia
Try your solution with this I/O (AFAIR, it's from old message board).
Input:
2 0.318
1 0.3
2 0.09
6 0.714285
6 0.714285000
1 0.9999
9 0.123456789
8 0.987654321
9 0.574454131
5 0.83777471
1 0.22222222
9 0.111111111
9 0.222222222
9 0.333333333
9 0.444444444
9 0.555555555
9 0.666666666
9 0.777777777
9 0.888888888
9 0.999999999
9 0.000000000
1 0.200
8 0.200000000
8 0.020000000
0 0.3
0 0.5
0 0.55
1 0.55
6 0.142857
0 0.9
1 0.9
6 0.076923
0 0.678453453
0 0.1
2 0.31818
9 0.345678993
2 0.25
1 0.3
0 0.3
0 0.0
5 0.99999
6 0.714285
0 0.5
0 0.35
1
Output:
Case 1: 7/22
Case 2: 1/3
Case 3: 1/11
Case 4: 5/7
Case 5: 119047381/166666500
Case 6: 1/1
Case 7: 13717421/111111111
Case 8: 54869684/55555555
Case 9: 574454131/999999999
Case 10: 41888317/49999500
Case 11: 2/9
Case 12: 1/9
Case 13: 2/9
Case 14: 1/3
Case 15: 4/9
Case 16: 5/9
Case 17: 2/3
Case 18: 7/9
Case 19: 8/9
Case 20: 1/1
Case 21: 0/1
Case 22: 1/5
Case 23: 1/5
Case 24: 2000000/99999999
Case 25: 3/10
Case 26: 1/2
Case 27: 11/20
Case 28: 5/9
Case 29: 1/7
Case 30: 9/10
Case 31: 1/1
Case 32: 1/13
Case 33: 678453453/1000000000
Case 34: 1/10
Case 35: 7/22
Case 36: 38408777/111111111
Case 37: 25/99
Case 38: 1/3
Case 39: 3/10
Case 40: 0/1
Case 41: 1/1
Case 42: 5/7
Case 43: 1/2
Case 44: 7/20
Input:
2 0.318
1 0.3
2 0.09
6 0.714285
6 0.714285000
1 0.9999
9 0.123456789
8 0.987654321
9 0.574454131
5 0.83777471
1 0.22222222
9 0.111111111
9 0.222222222
9 0.333333333
9 0.444444444
9 0.555555555
9 0.666666666
9 0.777777777
9 0.888888888
9 0.999999999
9 0.000000000
1 0.200
8 0.200000000
8 0.020000000
0 0.3
0 0.5
0 0.55
1 0.55
6 0.142857
0 0.9
1 0.9
6 0.076923
0 0.678453453
0 0.1
2 0.31818
9 0.345678993
2 0.25
1 0.3
0 0.3
0 0.0
5 0.99999
6 0.714285
0 0.5
0 0.35
1
Output:
Case 1: 7/22
Case 2: 1/3
Case 3: 1/11
Case 4: 5/7
Case 5: 119047381/166666500
Case 6: 1/1
Case 7: 13717421/111111111
Case 8: 54869684/55555555
Case 9: 574454131/999999999
Case 10: 41888317/49999500
Case 11: 2/9
Case 12: 1/9
Case 13: 2/9
Case 14: 1/3
Case 15: 4/9
Case 16: 5/9
Case 17: 2/3
Case 18: 7/9
Case 19: 8/9
Case 20: 1/1
Case 21: 0/1
Case 22: 1/5
Case 23: 1/5
Case 24: 2000000/99999999
Case 25: 3/10
Case 26: 1/2
Case 27: 11/20
Case 28: 5/9
Case 29: 1/7
Case 30: 9/10
Case 31: 1/1
Case 32: 1/13
Case 33: 678453453/1000000000
Case 34: 1/10
Case 35: 7/22
Case 36: 38408777/111111111
Case 37: 25/99
Case 38: 1/3
Case 39: 3/10
Case 40: 0/1
Case 41: 1/1
Case 42: 5/7
Case 43: 1/2
Case 44: 7/20
Got PE
Thank u a lot!!!
The problem with my one was that I was using unsigned long, so I've changed it to unsigned long long and got PE. I'll see what's still wrong in my output later...
Thanx..............
Jo
The problem with my one was that I was using unsigned long, so I've changed it to unsigned long long and got PE. I'll see what's still wrong in my output later...
Thanx..............
Jo
Could anybody help me out? my output matches the above tests
exactly, but I still get WA. any ideas?
Here's me code, I'll delete it if anybody helps me out.
exactly, but I still get WA. any ideas?
Here's me code, I'll delete it if anybody helps me out.
Last edited by broderic on Tue Aug 13, 2002 6:47 am, edited 1 time in total.
a few suggestions
1. try not to use double.
2. when you output, no need to output the numbers as 11 characters.
2. when you output, no need to output the numbers as 11 characters.
Fix my problem
Can anyone tell me where is my fault:
#include <stdio.h>
#include <math.h>
double gcd(double m,double n)
{
double r=fmod(m,n);
while(r)
{
m=n;
n=r;
r=fmod(m,n);
}
return n;
}
void main(void)
{
double cse=1,x,nn,dd,j,k,div,pp,d,f;
unsigned long long dummy;
double dum;
while(2==scanf("%lf%lf",&j,&x) && j!=1)
{
if(x==0)
{
printf("Case %0.lf: 0/1\n",cse++);
continue;
}
f=1;
nn=x*pow(10,j);
for(k=0;;k++)
{
dummy=nn;
dum=dummy;
if(dum==nn)break;
nn*=10;
f*=10;
}
if(j)
{
modf((x*pow(10,k)),&d);
nn=d;
dd=pow(10,k+j)pow(10,k);
}
else dd=f;
div=gcd(dd,nn);
printf("Case %0.lf: %.0lf/%.0lf\n",cse++,nn/div,dd/div);
}
}
#include <stdio.h>
#include <math.h>
double gcd(double m,double n)
{
double r=fmod(m,n);
while(r)
{
m=n;
n=r;
r=fmod(m,n);
}
return n;
}
void main(void)
{
double cse=1,x,nn,dd,j,k,div,pp,d,f;
unsigned long long dummy;
double dum;
while(2==scanf("%lf%lf",&j,&x) && j!=1)
{
if(x==0)
{
printf("Case %0.lf: 0/1\n",cse++);
continue;
}
f=1;
nn=x*pow(10,j);
for(k=0;;k++)
{
dummy=nn;
dum=dummy;
if(dum==nn)break;
nn*=10;
f*=10;
}
if(j)
{
modf((x*pow(10,k)),&d);
nn=d;
dd=pow(10,k+j)pow(10,k);
}
else dd=f;
div=gcd(dd,nn);
printf("Case %0.lf: %.0lf/%.0lf\n",cse++,nn/div,dd/div);
}
}
about 332 P.E.
Could anyone tell me why I got P.E.
Is there any wrong about the presentation?
I see only 18 Accepted and many (P.E.)s
Is there any wrong about the presentation?
I see only 18 Accepted and many (P.E.)s