[algogeeks] Re: largest Number Smaller Than Given Number

2006-03-07 Thread SPX2
Dhyanesh im not very sure about previous permuatation The question is. Is the prev_permutation() smaller in lexicographic order from the current one ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: largest Number Smaller Than Given Number

2006-03-02 Thread milochen
Ok... I know what' wrong with my thinking. My thinking was just by feeling but not logical. Suppose S is arbitrary sequence mapping some unsigned integer For any subsequence ,S' with lenght=n, of sequence S exist permutation f s.t.value f(S') value S' - S' is not non-decreasing

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-28 Thread Malay Bag
//N=no of digit of n; //ar[0]=10; for i=1,N a[i]=ith digit of n from left i=N-1; while(ar[i]ar[i+1])i--; if(i==0)return ;//i.e no answer j = N; while(ar[i]ar[j])j--; swap( ar[i],ar[j]);

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-28 Thread Ishu
Hi Juvexp, This does not seem to work for values such as 312, the correct output should be 231 but this gives the output as 132. Please correct me if i am wrong. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-27 Thread Dont Know
@Juvexp Thats the perfect solution (I think). I missed the sorting part when I worked on it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-27 Thread [EMAIL PROTECTED]
To daizi sheng: great solution.both shorter and faster than mine. --~--~-~--~~~---~--~~ 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

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-27 Thread Dhyanesh
Hi The function I used is previous permutation of STL. #include algorithm #include cstdio using namespace std; char buff[100]; int main(void) { int no = 23245; sprintf(buff,%d,no); if ( prev_permutation(buff, buff+strlen(buff) ) ) { printf(%s,buff); } else printf(You have smallest

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-27 Thread milochen
Does it always have the solution? What about that 123456789 ? I think that it doesn't always have solution for all case. I am sorry that I couldn't give you a C++ code , since I have no complier,so I couldn't ensure whether the code will be compile successful. Assume X=(x_1,x_2,x_3,

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-27 Thread ajay mishra
@milochen Your approach is not correct. I am giving a counter examplesay our input is 423, so by ur approach the solution is 243 or 234but the correct answer is 342.The approach given by dhyanesh and dazi is correct. On 2/28/06, milochen [EMAIL PROTECTED] wrote: Does it always have the

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-26 Thread daizi sheng
give u some ideas: for 11261 1st try: keep prefix 112 without beening changed the remaining number is 61 can we descrease the first digit (it is 6) ? yes so decrease it to the largest possible digit (that is 1) so change 61 - 16 so the answer is 11216 if we fail in the 1st try, we

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-26 Thread Dont Know
@daizi sheng Thanks for Ur ideas. But in Ur solution how do u fix the prefix. ie., How did U choose 112 as the prefix in the number 11261. Can u pls provide the algo. @Ajay U are correct. for the first example I gave, I made a mistake. So, I will define the problem again. Sorry

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-26 Thread Dhyanesh
This should work prev_permutation ( )-DhyaneshOn 2/26/06, Dont Know [EMAIL PROTECTED] wrote:@daizi sheng Thanks for Ur ideas.But in Ur solution how dou fix the prefix. ie., How did U choose 112 as the prefix in the number 11261.Canu pls provide the algo.@Ajay U are correct.for the first example I

[algogeeks] Re: largest Number Smaller Than Given Number

2006-02-26 Thread Dont Know
Thanks Ajay... I got some Idea. I will work on it. --~--~-~--~~~---~--~~ 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