Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import java.util.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class BestShuffle {
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ public class BestShuffle {
|
|||
|
||||
public static String bestShuffle(final String s1) {
|
||||
char[] s2 = s1.toCharArray();
|
||||
Collections.shuffle(Arrays.asList(s2));
|
||||
shuffle(s2);
|
||||
for (int i = 0; i < s2.length; i++) {
|
||||
if (s2[i] != s1.charAt(i))
|
||||
continue;
|
||||
|
|
@ -26,6 +26,16 @@ public class BestShuffle {
|
|||
return s1 + " " + new String(s2) + " (" + count(s1, s2) + ")";
|
||||
}
|
||||
|
||||
public static void shuffle(char[] text) {
|
||||
Random rand = new Random();
|
||||
for (int i = text.length - 1; i > 0; i--) {
|
||||
int r = rand.nextInt(i + 1);
|
||||
char tmp = text[i];
|
||||
text[i] = text[r];
|
||||
text[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
private static int count(final String s1, final char[] s2) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < s2.length; i++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue