@yellow
your code turns 1000,100,10,2270,12130 to 1,1,1,27,123 repectively....
simply it removes all trailing zeros ...

On Wed, Sep 22, 2010 at 8:10 PM, Yellow Sapphire <[email protected]>wrote:

> My Solution.
>
> Almost same as above but the flag is set by using bits.
>
> #define SETFLAG(flag, pos) (flag=flag | (1<<pos-1))
> #define IS_FLAG_SET(flag,pos) (flag & (1<<pos-1))
>
> int remove_dup(int n)
> {
>        int temp=0, temp2=0;
>        unsigned int flag=0;
>
>        /*
>         * Reverse the number
>         */
>        while (n>0 && (temp=temp*10 + n%10), n=n/10);
>
>        /*
>         * Find duplicates by setting the bits in the flag
>         */
>        n=temp;
>        temp=0;
>        while (n>0) {
>                temp2=n%10;
>                if(!IS_FLAG_SET(flag, temp2)) {
>                        temp=temp*10 + temp2;
>                        SETFLAG(flag, temp2);
>                }
>                n=n/10;
>        }
>        return temp;
> }
>
> --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
.... :-)
*****************************************
Nishant Agarwal
Computer Science and Engineering
NIT Allahabad
*****************************************

-- 
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.

Reply via email to