10922 - 2 the 9s
Moderator: Board moderators
-
- 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?
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?
Check out http://www.algorithmist.com !
Re: 10922 - 2 the 9s
sorry , I forgot log inAnonymous wrote:it should beLarry 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 sholud be
when input 999999999999999999999
We count f (189)
Re: 10922 - 2 the 9s
Just compute the sum recursively while it >9.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?
But, to know that sum of 9 is 9 you should compute it once,
thats why f('9') = 1.
-
- 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..
Check out http://www.algorithmist.com !
scanf is enough
Code: Select all
scanf("%s", temp);
btw, using gets, just ignoring non-digit characters, it works also
![:)](./images/smilies/icon_smile.gif)
Sorry For My Poor English.. ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- 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..
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..
Check out http://www.algorithmist.com !
-
- New poster
- Posts: 36
- Joined: Mon Jun 19, 2006 5:43 pm
- Location: Bangladesh
- 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.
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.
-
- Experienced poster
- Posts: 161
- Joined: Tue Oct 25, 2005 8:38 pm
- Location: buet, dhaka, bangladesh
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
this is toooooooo slow. use
or
your process call the function strlen(), "lenght of the string" times.
remove the copy() function
sprintf(stDiv, "%d", div); will do what you want
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++)
Code: Select all
for(int i = 0; str[i] ; i++)
Code: Select all
len = strlen(str);
for(int i = 0; i < len; i++)
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
----------------
the world is nothing but a good program, and we are all some instances of the program
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
Deena,
its an easy problem. Just do with Recursive method. OK
Example:
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.
-
- New poster
- Posts: 36
- Joined: Mon Jun 19, 2006 5:43 pm
- Location: Bangladesh
- Contact:
thnx
Thank u so much, ayon.
stupid strlen() was d culprit.
I get AC.
THANKS AGAIN.
take care.
stupid strlen() was d culprit.
I get AC.
THANKS AGAIN.
take care.
-
- New poster
- Posts: 36
- Joined: Mon Jun 19, 2006 5:43 pm
- Location: Bangladesh
- Contact:
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???
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???
The problem states...
Hope it helps.
I interpreted this line as 'take a number and sum its digits, and find the depth using that sum'.A well-known trick to know if an integer N is a multiple of nine is to compute the sum S of its digits. If S is a multiple of nine, then so is N
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage