how about this shorter solution,:)

int go(unsigned int n)
{
        int c[10] = {0},i,d,cur;
        for(cur = 1;cur <= n;cur *= 10) {
                d = n / cur % 10;
                c[d]++;
                for(i = d - 1;i >= 0;i--) if(c[i]) {
                        d = n / (cur * 10);
                        d = d * 10 + i;
                        c[i]--;
                        for(i = 9;i >= 0;i--) {
                                while(c[i]--) d = d * 10 + i;
                        }
                        return d;
                }
        }
        return -1;
}

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to