## 10922 - 2 the 9s

Moderator: Board moderators

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

### 10922 - 2 the 9s

I keep getting WA, so I'm not sure if I'm understanding it right.

f(999999999999999999999) =
f(189) + 1 =
f(18) + 2 =
f(9) + 3

and since 9 has 9-degree 1 (as given), doesn't that contradict the first case?

SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

### Re: 10922 - 2 the 9s

Anonymous wrote:
Larry wrote:I keep getting WA, so I'm not sure if I'm understanding it right.

f(999999999999999999999) =
f(189) + 1 =
f(18) + 2 =
f(9) + 3

and since 9 has 9-degree 1 (as given), doesn't that contradict the first case?
it should be
It sholud be
when input 999999999999999999999
We count f (189)

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
Not sure what you mean...

kp
Learning poster
Posts: 71
Joined: Tue Apr 26, 2005 1:29 am
Location: Russia

### Re: 10922 - 2 the 9s

Larry wrote:I keep getting WA, so I'm not sure if I'm understanding it right.

f(999999999999999999999) =
f(189) + 1 =
f(18) + 2 =
f(9) + 3

and since 9 has 9-degree 1 (as given), doesn't that contradict the first case?
Just compute the sum recursively while it >9.

But, to know that sum of 9 is 9 you should compute it once,
thats why f('9') = 1.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
Thanks. I changed my input reading from gets to scanf and it worked. I guess there were spaces somewhere..

SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan
Larry wrote:Thanks. I changed my input reading from gets to scanf and it worked. I guess there were spaces somewhere..
no , use gets can get ac

wook
Learning poster
Posts: 76
Joined: Fri Oct 01, 2004 11:34 am
Location: Korea, Republic Of

### scanf is enough

Code: Select all

``scanf("%s", temp);``
is enough.

btw, using gets, just ignoring non-digit characters, it works also
Sorry For My Poor English..

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
You can always emulate scanf with gets, but the point is that's the only change I made, and got AC. I presume everything is in [0-9], so if there's a space in the beginning or the end of a line, it'll be wrong for me.. and seems to be the case.

Just a heads up to others. I'm sure you can solve it using gets, just that then you'll have another case to worry about..

deena sultana
New poster
Posts: 36
Joined: Mon Jun 19, 2006 5:43 pm
Contact:

### 10922 - 2 the 9s

friends, my 10922 code got TLE.

how can speed up my code? any suggestion?

What i did, the summary is:
1. first i take all inputs in str.
2. then add themi div, and chek if (div%9==0);
3. if not then "not diveded by 9"
4.if yes then calculate the 9-degree by calling the summation n copy function untill div>9.
thats all.

now, i m looking 4 d kind person, who like 2 help me.

Code: Select all

``````CODE:

``````
Last edited by deena sultana on Mon Jun 19, 2006 7:47 pm, edited 3 times in total.

ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
use code tag so that codes are easily readable.

use "search" button, search for 10922, you will find already discusses topics about the problem

do not use

Code: Select all

``for(int i=0;i<strlen(str);i++)``
this is toooooooo slow. use

Code: Select all

``for(int i = 0; str[i] ; i++)``
or

Code: Select all

``````len = strlen(str);
for(int i = 0; i < len; i++)``````
your process call the function strlen(), "lenght of the string" times.

remove the copy() function
sprintf(stDiv, "%d", div); will do what you want
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm
Deena,
its an easy problem. Just do with Recursive method. OK
Example:

Code: Select all

``````999999999999999999999  = S(189) so its 1
then
189 = S(18) so its 2
then
18 = S(9) so its 3

hope you got it. ;)
and also will get accepted.``````
Last edited by asif_rahman0 on Mon Jun 19, 2006 7:56 pm, edited 1 time in total.

deena sultana
New poster
Posts: 36
Joined: Mon Jun 19, 2006 5:43 pm
Contact:

### thnx

Thank u so much, ayon.
stupid strlen() was d culprit.
I get AC.

THANKS AGAIN.

take care.

deena sultana
New poster
Posts: 36
Joined: Mon Jun 19, 2006 5:43 pm
Contact:
Asif, thanx 4 ur post.
i get d prob AC, by following Ayon's suggestion.
Thanks anyway. u people r so helpful.
take care.

<:3)~~
New poster
Posts: 16
Joined: Wed Dec 06, 2006 6:57 pm

### 10922 - 2 the 9s

they are saying that we have to find recursion depth..
and that 9 has a depth 1.
9-->1.
Now consider
99999...(21 9's)--->189--->18---->9--->1.
the depth shuld be 4.
but they are saying it to b 3.
Also consider 108.
108--->9--->1.
i think it should be 2.
Am i right???

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm