Hi,
Can anyone help me to find the bug in this code. The output looks
correct to me. So, I am sure I am missing something in understanding
the problem.
{
        String number = input.nextLine();
        char digits[] = new char[number.length()];
        for(int i=0; i<number.length(); i++) {
                digits[i] = number.charAt(i);
        }
        boolean solFound = false;
        for(int i=digits.length -2; i >=0; i--) {
                if(digits[i] < digits[i+1]) {
                        Arrays.sort(digits, i+1, digits.length);
                        if(digits[i] < digits[i+1]) {
                                char c = digits[i];
                                digits[i] = digits[i+1];
                                digits[i+1] = c;
                                solFound = true;
                                break;
                        }
                        else {
                                for(int j=i+2; j<digits.length; j++) {
                                        if(digits[i] < digits[j]) {
                                                char c = digits[i];
                                                digits[i] = digits[j];
                                                digits[j] = c;
                                                solFound = true;
                                                break;
                                        }
                                }
                                if(solFound) break;
                        }
                }
        }
        if(!solFound) {
                char[] newDigits = new char[digits.length +1];
                System.arraycopy(digits, 0, newDigits, 0, digits.length);
                newDigits[newDigits.length-1] = '0';
                Arrays.sort(newDigits, 1,  newDigits.length);
                digits = newDigits;
        }
        output.write(" " + new String(digits));
        output.flush();
}


Thanks
On Sep 13, 3:00 am, "David M." <[email protected]> wrote:
> 8000.Only can use an eight and all zeros you want...
>
> 2009/9/12 sep <[email protected]>
>
>
>
>
>
> > The number is 800
>
> > The next number is 8000 or 1008?????- Hide quoted text -
>
> - Show quoted text -

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" 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/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to