#include<iostream>
#include<conio.h>
#include<string.h>
#define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c)
using namespace std;
int main()
{
    char str[100],t;
    cin>>str;

    int len=strlen(str);
 int i,x,boo=1;
    for(i=len-1;i>0&&boo;i--)
    {
        for(x=i-1;x>=0&&boo;x--)
        {
            if(str[x]<str[i])
            {
            swap(str[x],str[i],t);
            boo=0;
            }
            }
            }
if(i>0)
{

//Sorting...
           for(int l=x+2;l<len-1;l++)
           {
                   int min=l;
                   for(int k=l+1;k<len;k++)
                   {
                           if(str[k]<str[min])
                           min=k;
                           }
                   swap(str[min],str[l],t);
                   }
}
    cout<<str;


 getch();
}


correct me..if m wrong..

On Thu, Sep 22, 2011 at 2:01 PM, Ratan <success.rata...@gmail.com> wrote:

> @dheeraj ... ya u r ryt.... thnxs for the correction
>
> On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma
> <dheerajsharma1...@gmail.com> wrote:
> > @Ratan:
> > i think the next largest here would be 784559
> >
> > On Thu, Sep 22, 2011 at 12:39 PM, Ratan <success.rata...@gmail.com>
> wrote:
> >>
> >> @kartik : to some extent ur code is giving the right answer... btw
> >> somehow check tis
> >> let for example the no be 759854
> >> then the next biggest no is 794558
> >> btw ur program is giving 795854 which is undoubtedly wrong............
> >> the code would give more appropriate result if u sort the numbers from
> >> from i to n on meeting the condition of (a[i-1]<a[i])
> >>
> >> On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma <
> ramakant...@gmail.com>
> >> wrote:
> >> > starting from right find first digit less then right most digit,if no
> >> > any
> >> > digit is less,then move to next right most and compair ,,,,when found
> >> > exchange those no,
> >> > now sort the no.s up to that index of the given no which is exchanged:
> >> > Ex:
> >> > 43987723893239876
> >> > first required sequence: 439877238932[3]987[6] swap these no
> >> > 439877238932[6]{987[3]}
> >> > now sort in decreasing order  439877238932[6]{3789} this is the
> required
> >> > no
> >> > ....correct me if any thing wrong
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Algorithm Geeks" group.
> >> > To post to this group, send email to algogeeks@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > algogeeks+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/algogeeks?hl=en.
> >> >
> >>
> >>
> >>
> >> --
> >> Ratan Kumar
> >> B. Tech
> >> MNNIT,
> >> Allahabad
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> >
> >
> > --
> > Dheeraj Sharma
> > Comp Engg.
> > NIT Kurukshetra
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> Ratan Kumar
> B. Tech
> MNNIT,
> Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to