275 - Expanding Fractions

Moderator: Board moderators

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
HAHA...
Now I got Accepted,
Thanks.

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
HAHAHA I've got AC.
Thanks,
RS

abboodi010
New poster
Posts: 4
Joined: Tue Apr 22, 2003 3:49 pm

p 275 emergency

how can i print this in C++

53 / 122
= .4344262295081967213114754098360655737704918032786
885245901639
The last 60 digits repeat forever.

if any body knwo the solutin of this whole problem(275)
abboodi010@hotmail.com

quikly[/cpp]

abboodi010
New poster
Posts: 4
Joined: Tue Apr 22, 2003 3:49 pm

i don`t understand this---?

[cpp]

first, i coudln't understand your code.
if you can could you write the alogrthem for your code , i really need it.

seconed

what is the meaning of this line
res[n_res++] = div+48;

could you explain to me how it works?

[/cpp]

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
Sure.

Code: Select all

``````My method is like this:
3 / 7 = ?
0.428571
/---------
7    /  30
28
------- -
20
14
-------  -
60
56
------ -
40
35
------- -
50
49
------- -
10
7
------- -

3  ->here you see the pattern repeated.``````
What I do is build a string division, and divide the number until we find the pattern repeated. (I save all the number during the division).

abboodi010
New poster
Posts: 4
Joined: Tue Apr 22, 2003 3:49 pm
[cpp]

thanx ,
but i still could'nt understand the working of (( div+48 ))

what is ( 48 ) doing here ?

note:.
this problem is my project in university
and I must submit the alogrithem within 2 weeks
so i do'nt have time because I have other courses
so if you can
could you write the alogarithem ,please?[/cpp]

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut
although that's not my code i think meaning of adding by 48 is to convert to ASCII code, since ASCII code for '0' is 48.
Kalo mau kaya, buat apa sekolah?

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
Yes, since ascii '0' is 48, so I use div+48, to make char '0', '1', '2', '3', '4', ....

'0' = 0 + 48;
'1' = 1 + 48;
'2' = 2 + 48;
'3' = 3 + 48;
'4' = 4 + 48;
etc.

abboodi010
New poster
Posts: 4
Joined: Tue Apr 22, 2003 3:49 pm
thanx alot ((Red Scorpion)) and ((titid_gede))

if u can send me alogrithm for this program
at my e_Mail.

this my e_mail
abboodi010@hotmail.com

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
Can someone post some examples?

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
INPUT

Code: Select all

``````0 1
1 9
3 9
1 7
426 989
878 953
126 650
179 626
224 444
95 952
438 704
0 0``````
OUTPUT

Code: Select all

``````.
This expansion terminates.

.1
The last 1 digits repeat forever.

.3
The last 1 digits repeat forever.

.142857
The last 6 digits repeat forever.

.4307381193124368048533872598584428715874620829120
32355915065722952477249747219413549039433771486349
84833164812942366026289180990899898887765419615773
50859453993933265925176946410515672396359959555106
16784630940343781597573306370070778564206268958543
98382204246713852376137512639029322548028311425682
50758341759352881698685540950455005055611729019211
32457027300303336703741152679474216380182002022244
69160768452982810920121334681496461071789686552072
8008088978766
The last 462 digits repeat forever.

.9213011542497376705141657922350472193074501573976
91500524658971668415529905561385099685204616998950
68205666316894018887722980062959076600209863588667
36621196222455403987408184679958027282266526757607
55508919202518363064008394543546694648478488982161
59496327387198321091290661070304302203567681007345
22560335781741867785939139559286463798530954879328
43651626442812172088142707240293809024134312696747
11437565582371458551941238195173137460650577124868
83525708289611752360965372507869884575026232948583
42077649527806925498426023084994753410283315844700
94438614900314795383001049317943336831059811122770
19937040923399790136411332633788037775445960125918
15320041972717733473242392444910807974816369359916
05456453305351521511017838405036726128016789087093
38929695697796432318992654774396642182581322140608
60440713536201469045120671563483735571878279118572
92759706190975865687303252885624344176285414480587
61804826862539349422875131164742917103882476390346
274
The last 952 digits repeat forever.

.19384615
The last 6 digits repeat forever.

.2859424920127795527156549520766773162939297124600
63897763578274760383386581469648562300319488817891
37380191693290734824281150159744408945686900958466
45367412140575079872204472843450479233226837060702
87539936102236421725239616613418530351437699680511
18210862619808306709265175718849840255591054313099
04153354632587
The last 312 digits repeat forever.

.504
The last 3 digits repeat forever.

.0997899159663865546218487394957983193277310924369
74
The last 48 digits repeat forever.

.6221590
The last 2 digits repeat forever.``````

sajib amin
New poster
Posts: 2
Joined: Sat Sep 13, 2003 4:05 pm

275-Why get WA

I got WA for the following code:

Code: Select all

``````#include<stdio.h>

void main()
{
int a,b,rem,quot,quo[40000],arem[40000];
int i,j,length,flag,start,total,fstln;

while(scanf("%d%d",&a,&b)==2 && a && b)
{
quot = a / b;
rem = a % b;
quo[0] = '.';

flag = 0;
for(i=1;;i++)
{
arem[i] = rem;
rem = rem * 10;
quot = rem / b;
rem = rem % b;

//check for repeating remainder
for(j=1;j<=i;j++)
if(arem[j] == rem) {
flag = 1;
break;
}

quo[i] = quot;
if(flag) {
start = j;
break;
}
}

total = i;

printf("%c",quo[0]);

for(j=1;j<total;j++)
{
if(j%50==0)
printf("\n");
printf("%d",quo[j]);

}

if(quo[total] != 0)
{
if(total%50==0)
printf("\n");
printf("%d",quo[i]);
}
printf("\n");

if(quo[total] != 0)
printf("The last %d digits repeat forever.\n\n",total-start+1);
else
printf("This expansion terminates.\n\n");

}

}

``````
Did i miss some something?
Would anybody check this code with some critical inputs.

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Contact:

Problem 275: Expanding Fraction

deleted later....
Last edited by Ferdous on Wed Mar 16, 2005 7:50 am, edited 1 time in total.
I am destined to live on this cruel world........

junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am
I didn't really read through your code, but the line char flag[1001] seems to say taht you use 100 digits to determine recurring digits...

I think that may not be enough.,. I'm using 1000000 digits and a recurrence of at least 3 times before I flag the recurring digits... it's an overkill, but it works. :p

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

STUPIDIEST MISTAKE

I want to share with you all my stupidiest mistake!!! From my experience, we only use plurals (in this case "digits") when the related quantity is more than 1. So even though it didn't say in this problem's description, I assumed it so and check if number of repeating digit is 1 or not, and print "digit" or "digits" respectively. Turns out the checking wasn't even necessary...