202  Repeating Decimals
Moderator: Board moderators

 New poster
 Posts: 10
 Joined: Mon Mar 14, 2005 7:35 am
202 Help ME!!!
I had tried all I could did, but IT SITLL WA!
Please help me! Thanks for you reply
Delete after AC
Here thanks again
Please help me! Thanks for you reply
Delete after AC
Here thanks again
Last edited by johnnydog33 on Thu May 05, 2005 11:06 am, edited 1 time in total.
It's normally a bad idea to just directly post your source
code and say "help ! " This is just for your information.
I mean you really attract more the attention of the other people
here, if you first describe with plain words what exactly
your problem is, what your algorithm you use and so on.
So ... What problems exactly do you have with problem 202 ?
Do you have some I/O from your program? Are
you sure you cover all test cases which you have
probably found in other threads dedicated to problem 202 ?
Here is some sample I/O for you ( and for anyone else who
might be interested ) from an ACC program.
Let me know if your program covers them all ( if it prints correct
answers for all the test cases given below ). This would mean
you really have some more specific problem / bug.
Regards!
INPUT
OUTPUT
code and say "help ! " This is just for your information.
I mean you really attract more the attention of the other people
here, if you first describe with plain words what exactly
your problem is, what your algorithm you use and so on.
So ... What problems exactly do you have with problem 202 ?
Do you have some I/O from your program? Are
you sure you cover all test cases which you have
probably found in other threads dedicated to problem 202 ?
Here is some sample I/O for you ( and for anyone else who
might be interested ) from an ACC program.
Let me know if your program covers them all ( if it prints correct
answers for all the test cases given below ). This would mean
you really have some more specific problem / bug.
Regards!
INPUT
Code: Select all
0 5
76 25
5 43
1 397
0 101
1 101
20 5
33 70
3 77
15 899
3 7
0 9
1 999
15 89
12 2999
12 1000
2999 3000
OUTPUT
Code: Select all
0/5 = 0.(0)
1 = number of digits in repeating cycle
76/25 = 3.04(0)
1 = number of digits in repeating cycle
5/43 = 0.(116279069767441860465)
21 = number of digits in repeating cycle
1/397 = 0.(00251889168765743073047858942065491183879093198992...)
99 = number of digits in repeating cycle
0/101 = 0.(0)
1 = number of digits in repeating cycle
1/101 = 0.(0099)
4 = number of digits in repeating cycle
20/5 = 4.(0)
1 = number of digits in repeating cycle
33/70 = 0.4(714285)
6 = number of digits in repeating cycle
3/77 = 0.(038961)
6 = number of digits in repeating cycle
15/899 = 0.(01668520578420467185761957730812013348164627363737...)
420 = number of digits in repeating cycle
3/7 = 0.(428571)
6 = number of digits in repeating cycle
0/9 = 0.(0)
1 = number of digits in repeating cycle
1/999 = 0.(001)
3 = number of digits in repeating cycle
15/89 = 0.(16853932584269662921348314606741573033707865)
44 = number of digits in repeating cycle
12/2999 = 0.(00400133377792597532510836945648549516505501833944...)
1499 = number of digits in repeating cycle
12/1000 = 0.012(0)
1 = number of digits in repeating cycle
2999/3000 = 0.999(6)
1 = number of digits in repeating cycle

 New poster
 Posts: 10
 Joined: Mon Mar 14, 2005 7:35 am

 New poster
 Posts: 10
 Joined: Mon Mar 14, 2005 7:35 am
202  Repeating Decimals
I check the test from other thread but it doesn't help.
I need more tests.
Can anybody help me?
Thank you in anticipation
I need more tests.
Can anybody help me?
Thank you in anticipation
You should try these inputs,
Input:
Output:
Hope it works.
Input:
Code: Select all
2772 883
22 7
678 119
1011 2123
1 303
1 300
Code: Select all
2772/883 = 3.(13929784824462061155152887882219705549263873159682...)
441 = number of digits in repeating cycle
22/7 = 3.(142857)
6 = number of digits in repeating cycle
678/119 = 5.(697478991596638655462184873949579831932773109243)
48 = number of digits in repeating cycle
1011/2123 = 0.(47621290626471973622232689590202543570419218087611...)
192 = number of digits in repeating cycle
1/303 = 0.(0033)
4 = number of digits in repeating cycle
1/300 = 0.00(3)
1 = number of digits in repeating cycle
Ami ekhono shopno dekhi...
HomePage
HomePage

 A great helper
 Posts: 383
 Joined: Mon Oct 18, 2004 8:25 am
 Location: Bangladesh
 Contact:
Ok then try the following inputs...
Input:
And the output is...
Output:
Hope it helps .
Input:
Code: Select all
0 3000
1 1
9 9
3000 2999
2999 2997
Output:
Code: Select all
0/3000 = 0.(0)
1 = number of digits in repeating cycle
1/1 = 1.(0)
1 = number of digits in repeating cycle
9/9 = 1.(0)
1 = number of digits in repeating cycle
3000/2999 = 1.(00033344448149383127709236412137379126375458486162...)
1499 = number of digits in repeating cycle
2999/2997 = 1.(000667334)
9 = number of digits in repeating cycle
Ami ekhono shopno dekhi...
HomePage
HomePage

 A great helper
 Posts: 383
 Joined: Mon Oct 18, 2004 8:25 am
 Location: Bangladesh
 Contact:
my program passes this i/o also
here is my code
what can i do now?
here is my code
Code: Select all
#include <iostream>
#include <stdio.h>
using namespace std;
#define max 30010
int num[max+1], n;
char digit[100000000];
int main (void)
{
int numerator, nominator;
int i, j, st, en;
while(scanf("%d%d",&numerator,&nominator)==2){
printf("%d%c%d = %d.",numerator,'/',nominator,numerator/nominator);
n=(numerator%nominator);
for(i=0;i<=nominator*10;i++)num[i]=0;
i=1;
while(1){
if(num[n]){
st=num[n];
en=i;
if(n<nominator && num[n*10])st=num[n*10];
break;
}
if(!n){
digit[i]='0';
i++;
st=i1;
en=i;
break;
}
num[n]=i;
if(n<nominator)n*=10;
num[n]=i;
while(n<nominator){
n*=10;
digit[i]='0';
i++;
num[n]=i;
}
digit[i]=(n/nominator)+'0';
n=n%nominator;
i++;
}
for(i=1;i<st;i++)cout<<digit[i];
cout<<"(";
for(i=st;i<en;i++){
if((ist)==50){
cout<<"...";
break;
}
cout<<digit[i];
}
cout<<")"<<endl;
printf(" %d = number of digits in repeating cycle\n\n",enst);
//digit[i+1]='\0';
//cout<<digit<<endl;
}
return 0;
}
Check the following input and output carefully...
Input:
Output:
But your code returns wrong answer.
And another thing. If the denominator is n there can me maximum n digits in repeating cycle... If the max denominator is 3000 there can be maximum 3000 digits in repeating cycle. So, you need an array like num[30001]. And why u are using the array digit[100000000], I don't understand.
Remember that if there are more than or exactly 50 digits in repeating cycle then you should print '...' otherwise not.
Best of Luck.
Input:
Code: Select all
1 397
10 397
100 397
1000 397
1 251
1 753
15 1255
Code: Select all
1/397 = 0.(00251889168765743073047858942065491183879093198992...)
99 = number of digits in repeating cycle
10/397 = 0.(02518891687657430730478589420654911838790931989924...)
99 = number of digits in repeating cycle
100/397 = 0.(25188916876574307304785894206549118387909319899244...)
99 = number of digits in repeating cycle
1000/397 = 2.(51889168765743073047858942065491183879093198992443...)
99 = number of digits in repeating cycle
1/251 = 0.(00398406374501992031872509960159362549800796812749...)
50 = number of digits in repeating cycle
1/753 = 0.(00132802124833997343957503320053120849933598937583...)
50 = number of digits in repeating cycle
15/1255 = 0.(01195219123505976095617529880478087649402390438247...)
50 = number of digits in repeating cycle
And another thing. If the denominator is n there can me maximum n digits in repeating cycle... If the max denominator is 3000 there can be maximum 3000 digits in repeating cycle. So, you need an array like num[30001]. And why u are using the array digit[100000000], I don't understand.
Remember that if there are more than or exactly 50 digits in repeating cycle then you should print '...' otherwise not.
Best of Luck.
Ami ekhono shopno dekhi...
HomePage
HomePage

 A great helper
 Posts: 383
 Joined: Mon Oct 18, 2004 8:25 am
 Location: Bangladesh
 Contact:
hi
i passed all the test cases found in the board.but WA.
please help.
i passed all the test cases found in the board.but WA.
please help.
Code: Select all
#include<stdio.h>
#include<string.h>
#define YES 1
#define NO 0
int gcd(int a,int b)
{
int c;
for(;a%b;c=b,b=a%b,a=c);
return b;
}
void main()
{
int x,y,found,z,ans,digit[3001],temp[3001],a,b;
/*freopen("d:\\out202.txt","w",stdout);*/
while(scanf("%d %d",&a,&b)==2 && a+b)
{
memset(digit,0,sizeof(digit));
memset(temp,0,sizeof(temp));
printf("%d/%d = %d",a,b,a/b);
x=gcd(a,b);
a/=x,b/=x;
a=a%b;
for(x=0,found=NO;x<3001;x++)
{
a*=10;
digit[x]=a/b;
temp[x]=a%b;
if(a%b==0)break;
for(y=0;y<x;y++)
if(temp[y]==temp[x])
{
found=YES;
break;
}
if(found)break;
a=a%b;
}
printf(".");
ans=xy;
if(!y && digit[x]==digit[y] && found)x;
if(!found)
{
if(x)x++;
for(y=0,z=2;y<x;y++,z++)
{
printf("%d",digit[y]);
}
printf("(%d)\n",0);
printf(" %d = number of digits in repeating cycle\n\n",1);
}
else
{
for(a=0;a<50;a++)
{
if(a==xans+1)printf("(");
if(a<=x)printf("%d",digit[a]);
else break;
}
if(x>=49)printf("...");
printf(")\n");
printf(" %d = number of digits in repeating cycle\n\n",ans);
}
}
}
Your code is almost ok.....
Just try this input. Your program returns wrong...
Input:
Output:
And another thing...
Though I think that there is no '49 repeating cycles' in range 03000.
But better to use '>=50'.
Hope it helps.
Just try this input. Your program returns wrong...
Input:
Code: Select all
1 2
Code: Select all
1/2 = 0.5(0)
1 = number of digits in repeating cycle
Code: Select all
if(x>=50)printf("...");//not> if(x>=49)printf("...");
But better to use '>=50'.
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage