thanks saif ........................accepted
11634 - Generate random numbers
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Wed Jul 22, 2009 9:10 pm
11634 - Generate random numbers
Last edited by sanjoy_sust on Sun Aug 09, 2009 9:33 am, edited 1 time in total.
-
- Learning poster
- Posts: 97
- Joined: Fri Aug 22, 2008 10:18 pm
- Location: CSE.SUST.SYLHET
Re: 11634 - Generate random numbers
input:Hi sonjoy ..............![]()
![]()
![]()
ur getting wa becoz...ur code gove wa out put for
this
Code: Select all
100
0
Code: Select all
1
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 11634 - Generate random numbers
I am getting WA. Whats wrong with my code?
Code: Select all
Accepted !!
Last edited by Shahidul.CSE on Sun Nov 30, 2014 4:09 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Re: 11634 - Generate random numbers
Input
Acc Output
Code: Select all
1
2
10
11
999
1000
0
Code: Select all
2
2
3
3
23
2
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 11634 - Generate random numbers
You could simplify your code. You can convert a number using sprintf to get 4 middle digits.
I use array used[10000] (initially set to 0) to mark previous numbers.
Now you can check in O(1) if a number was already used. ![:)](./images/smilies/icon_smile.gif)
Code: Select all
sprintf(s, "%08d", n * n);
for (n = 0, i = 2; i < 6; i++) n = n * 10 + s[i] - '0';
Code: Select all
used[n] = 1
![:)](./images/smilies/icon_smile.gif)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 11634 - Generate random numbers
Thanks lighted! Got AC now!! ![:D](./images/smilies/icon_biggrin.gif)
My mistake was not considering 0 as a new random number. Before counting it, I stopped, which was wrong. :p
I am sending you my modified code in PM.![:)](./images/smilies/icon_smile.gif)
![:D](./images/smilies/icon_biggrin.gif)
My mistake was not considering 0 as a new random number. Before counting it, I stopped, which was wrong. :p
I am sending you my modified code in PM.
![:)](./images/smilies/icon_smile.gif)
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com