## 11113 - Continuous Fractions

Moderator: Board moderators

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Contact:
sapnil wrote:Whats wrong in my code plz help me.
What is judge response?

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

### Re: 11113 - Continuous Fractions

I'm getting too many WR again. Plz help me

Code:

Code: Select all

``````#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<math.h>

#include<algorithm>
using namespace std;

#define CSE 20009

long long a[CSE],top;

long long Digit_cnt(long long num)
{
long long c;

c=0;

while(num>0)
{
num=num/10;
c++;
}

return c;
}

void Find(long long m,long long n)
{
top=0;
while( n )
{
a[top++]=( m / n );
m %= n;
m ^= n ^= m ^= n;
}

return;
}

int main()
{
//freopen("aa.out","w",stdout);
long long u,d,i,s,y,Total,ts,t,j,p,cc=1,tt,vv,pp;

while(scanf("%lld %lld",&u,&d)==2)
{
if(u==0 && d==0)
{
break;
}
printf("Case %lld:\n",cc++);
printf("%lld / %lld\n",u,d);
Find(u,d);

if(a[top-1]>1)
{
a[top-1]--;
a[top]=1;
top++;
}

s=0;
for(i=0;i<top;i++)
{
//printf("%lld ",a[i]);
y=Digit_cnt(a[i]);
y--;
s+=y;
}
//printf("\n");

Total=(top-1)*4+1+s;
//printf("Total; %lld\n",Total);

ts=0;
t=Total;
tt=0;
vv=0;
pp=0;
for(i=0;i<top-1;i++)
{
y=Digit_cnt(a[i]);
y--;
//ts=ts+y;
ts=y;
tt+=y;
for(j=0;j<tt;j++)
{
printf(".");
}
for(j=0;j<(i+1)*4;j++)
{
printf(".");
}
p=0;
t=t-ts-4;
//t=t-ts-4-tt;
if(t%2==0)
{
p=1;
}
for(j=0;j<t/2-p;j++)
{
printf(".");
}
printf("1");
for(j=0;j<t/2;j++)
{
printf(".");
}
printf("\n");

if(pp)
{
vv=i*4+tt;
}
else
{
vv=i*4;
}

pp=1;
for(j=0;j<vv-Digit_cnt(a[i])+1;j++)
{
printf(".");
}
printf("%lld.+.",a[i]);

pp=1;
for(j=0;j<t;j++)
{
printf("-");
}
printf("\n");
}
for(j=0;j<Total-1;j++)
{
printf(".");
}
printf("%lld\n",a[top-1]);
}

return 0;
}
``````
Thanks
Keep Posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@