202-why WA?

All about problems in Volume II. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

202-why WA?

Postby joshila21 » Sun Jul 11, 2004 11:17 pm

i don't know what is wrong with this code.
it seems OK! to me.
can anyone help me to findout the mistake?



#include <stdio.h>

int fraction[5000],numerator[5000];

int main()
{
int i,j,k,n,a,b,remainder_a_b,rem,sd=0,exception,minus_;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(sd)printf("\n");
(rem=a,i=0,k=0,exception=0,minus_=0);
remainder_a_b=(a%b);
numerator[i++]=a;
a=remainder_a_b*10;
while(1)
{
while(b>a)
{
numerator[i]=a;
for(j=0;j<i;j++)
if(a==numerator[j])
{
minus_=j;
goto L1;
}
i++;
a*=10;
fraction[k++]=0;
}
for(j=0;j<i && k;j++)
if(a==numerator[j])
{
minus_=j;
break;
}
if(j<i && k)break;
numerator[i++]=a;
fraction[k++]=a/b;
remainder_a_b=(a%b);
if(remainder_a_b)
a=remainder_a_b*10;
else
exception=1;
}
L1:
if(exception)
printf("%d/%d = %d.",rem,b,rem/b);
else
printf("%d/%d = %d.",rem,b,rem/b);
if(!minus_)printf("(");
for(j=0;j<k;j++)
{
if(minus_ && k-(k-minus_+1)==j && !exception)printf("(");
printf("%d",fraction[j]);
if(j==49)
{
printf("...");
break;
}
}
if(exception)
printf("(0)\n 1 = number of degits in repeating cycle\n");
else
{
if(minus_)k=k-minus_+1;
printf(")\n %d = number of degits in repeating cycle\n",k);
}
sd=1;
}
return 0;
}
be a good man
joshila21
New poster
 
Posts: 5
Joined: Fri May 07, 2004 12:15 am
Location: bangladesh

Re: 202-why WA?

Postby brianfry713 » Fri Sep 02, 2011 11:00 pm

Check that you're using three spaces before the number not one - the forum software takes out extra spaces.

Also add a newline at the end of the output.
Last edited by brianfry713 on Fri Dec 16, 2011 8:14 pm, edited 1 time in total.
brianfry713
Guru
 
Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 202-why WA?

Postby plamplam » Thu Sep 22, 2011 8:44 am

Code: Select all
15 3
1 2971


Code: Select all
15/3 = 5.(0)
   1 = number of digits in repeating cycle

1/2971 = 0.(00033658700774150117805452709525412319084483338943...)
   2970 = number of digits in repeating cycle

You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
User avatar
plamplam
Experienced poster
 
Posts: 151
Joined: Fri May 06, 2011 11:37 am


Return to Volume II

Who is online

Users browsing this forum: No registered users and 1 guest