@Navneet, i mean the length of N is less than 1000, not the value of N .
*so, N maybe cannot be represented in 32bit . 10^1000-1 is huge number~~
*
2011/10/9 Navneet <[email protected]>
> sumOfDigits(i) - simply sums all the digits and returns the value.
> sortDigits() - takes a number and return the lowest possible number
> possible with digits of param passed.
> flag = false;
>
> for(int i=n+1, i < 1000; i++) //mention to go upto 1000 in problem
> {
> if(sumOfDigits(i) == sumOfDigits(n))
> {
> //a candidate
> int sorted i = sortDigits(i);
> int sorted n = sortDigits(n);
> if(i == n)
> {
> //we found one
> cout<<"\nDesired number is "<<i<<endl; //may abort or continue to find
> more
> flag = true;
> }
> }
> if(!flag)
> cout<<"\nNo such number found"<<endl;
> }
>
> On Oct 9, 5:04 pm, wujin chen <[email protected]> wrote:
> > @Aamir , yes, for some N, it will be no ans, then return -1.
> >
> > 2011/10/9 Aamir Khan <[email protected]>
> >
> >
> >
> >
> >
> >
> >
> > > Answer won't be possible in for each N. What would be answer for N=999
> ?
> >
> > > On Sun, Oct 9, 2011 at 4:22 PM, Ankur Garg <[email protected]>
> wrote:
> >
> > >> Is it sum of bits or sum of digits ?
> >
> > >> On Sun, Oct 9, 2011 at 1:39 PM, wujin chen <[email protected]
> >wrote:
> >
> > >>> Given a positive number N, find a minimum number M greater than N, M
> has
> > >>> the same length with N and the sum of the bits are equal.
> >
> > >>> example:
> > >>> N=134 , M=143, // 1+3+4=1+4+3
> > >>> N=020, M = 101, //2=1+1
> >
> > >>> the length of N is less than 1000.
> >
> > >>> --
> > >>> You received this message because you are subscribed to the Google
> Groups
> > >>> "Algorithm Geeks" group.
> > >>> To post to this group, send email to [email protected].
> > >>> To unsubscribe from this group, send email to
> > >>> [email protected].
> > >>> For more options, visit this group at
> > >>>http://groups.google.com/group/algogeeks?hl=en.
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> Groups
> > >> "Algorithm Geeks" group.
> > >> To post to this group, send email to [email protected].
> > >> To unsubscribe from this group, send email to
> > >> [email protected].
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > Aamir Khan | 3rd Year | Computer Science & Engineering | IIT Roorkee
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.