Here's the code
int rem_dup(int n)
{
int *a,i,c,t,d,count[10]={0},arr[20],j=0,sum=0;
a=(int *)malloc(sizeof(a));
for(i=0;n>0;i++)//storing each digit of number in an array
{
a[i]=n%10;
n=n/10;
}
c=d=i-1;
i=0;
while(i<c)//reversing the array
{
t=a[i];
a[i++]=a[c];
a[c--]=t;
}
for(i=0;i<=d;i++)//setting repeated digits to -1
{ if(count[a[i]]==0)
count[a[i]]++;
else
a[i]=-1;
}
for(i=0,j=0;i<=d;i++) //storing all non repeating digits in anothor
array arr[]
{
if(a[i]!=-1)
{
arr[j]=a[i];
j++;
}
}
for(i=0;i<j;i++)
sum=sum+arr[i]*power(10,j-i-1);
return sum;
}
On Thu, Sep 23, 2010 at 12:39 AM, Dave <[email protected]> wrote:
> @Saurabh: Doesn't this turn 10 into 1? You need to count the digits in
> the number as you are reversing it, and replace the second while loop
> with a for loop with that many iterations.
>
> Dave
>
> On Sep 21, 11:28 pm, saurabh agrawal <[email protected]> wrote:
> > @dave:
> > your code is producing 4526 for input=24526 instead of 2456
> > Here's corrected code :)
> > /////////CODE///////////////
> > int function(int n){
> > int a[10]={0},temp=0,result =0;
> > while(n){ //reverse the number..
> > temp=10*temp+n%10;
> > n/=10;
> > }
> > n=temp;
> > while(n){ ///remove duplicate digits...
> > if(a[n%10]==0){
> > a[n%10]=1;
> > result=10*result+n%10;
> > }
> > n/=10;
> > }
> > return result;}
> >
> > ///////////////END/////////////////////
> >
> >
> >
> > On Wed, Sep 22, 2010 at 8:51 AM, Dave <[email protected]> wrote:
> > > @Saurabh: Doesn't your code turn 123 into 321? Try this:
> >
> > > int function(int n)
> > > {
> > > int a[10]={0};
> > > int result=0;
> > > int place=1;
> > > while(n){
> > > if(a[n%10]==0){
> > > a[n%10]=1;
> > > result+=(n%10)*place;
> > > place*=10;
> > > }
> > > n/=10;
> > > }
> > > return result;
> > > }
> >
> > > Dave
> >
> > > On Sep 21, 3:12 pm, saurabh agrawal <[email protected]> wrote:
> > > > int function(int n){
> >
> > > > int a[10]={0};
> > > > int result =0;
> > > > while(n){
> > > > if(a[n%10]==0){
> > > > a[n%10]=1;
> > > > result=10*result+n%10;
> > > > }
> > > > n/=10;}
> >
> > > > return result;`
> >
> > > > }
> > > > On Wed, Sep 22, 2010 at 12:39 AM, Albert <[email protected]>
> > > wrote:
> > > > > Given a number find the number by eliminating the duplicate digits
> in
> > > > > the number..
> >
> > > > > for eg: 24526 ans is 2456
> > > > > .....
> >
> > > > > int function(int n)
> > > > > {
> >
> > > > > .
> > > > > .
> > > > > .
> >
> > > > > }
> >
> > > > > Give all sort of solutions to this problem.....
> >
> > > > > Efficiency in the code is important ....
> >
> > > > > --
> > > > > 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]>
> <algogeeks%2bunsubscr...@googlegroups.com>
> > > <algogeeks%2bunsubscr...@googlegroups.com>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > --
> > > 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]>
> <algogeeks%2bunsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.