Cool, Sumudu, with your suggestion I was able to shorten my code by half! So
it's pretty short even without next_permutation(). But that basically means
that if someone has next permutation they could solve it with almost no code
at all.
StreamReader reader = new StreamReader("input.in");
StreamWriter writer = new StreamWriter("output.out", false);
int numCases = int.Parse(reader.ReadLine());
for (int i = 0; i < numCases; i++) {
string j = "0"+reader.ReadLine();
int l = j.Length;
 for (int k = l - 2; k > -1; k--) {
if (j[k] < j[k + 1]) {
int m = k + 1;
 for (int n = m + 1; n < l; n++) {
if (j[n] > j[k]) {
m = n;
 }
}
j = j.Substring(0, k) + j[m] + new string((j.Substring(k + 1, m - k - 1) +
j[k] + j.Substring(m + 1)).Reverse().ToArray());
 if (j[0] == '0') {
writer.WriteLine("Case #{0}: {1}", i + 1, j.Substring(1));
 } else {
writer.WriteLine("Case #{0}: {1}", i + 1, j);
}
 break;
}
}
}
reader.Close();
writer.Close();

--~--~---------~--~----~------------~-------~--~----~
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