Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
import java.util.*;
|
||||
|
||||
public class IntConcat {
|
||||
|
||||
private static Comparator<Integer> sorter = new Comparator<Integer>(){
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2){
|
||||
String o1s = o1.toString();
|
||||
String o2s = o2.toString();
|
||||
|
||||
if(o1s.length() == o2s.length()){
|
||||
return o2s.compareTo(o1s);
|
||||
}
|
||||
|
||||
int mlen = Math.max(o1s.length(), o2s.length());
|
||||
while(o1s.length() < mlen * 2) o1s += o1s;
|
||||
while(o2s.length() < mlen * 2) o2s += o2s;
|
||||
|
||||
return o2s.compareTo(o1s);
|
||||
}
|
||||
};
|
||||
|
||||
public static String join(List<?> things){
|
||||
String output = "";
|
||||
for(Object obj:things){
|
||||
output += obj;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
List<Integer> ints1 = new ArrayList<Integer>(Arrays.asList(1, 34, 3, 98, 9, 76, 45, 4));
|
||||
|
||||
Collections.sort(ints1, sorter);
|
||||
System.out.println(join(ints1));
|
||||
|
||||
List<Integer> ints2 = new ArrayList<Integer>(Arrays.asList(54, 546, 548, 60));
|
||||
|
||||
Collections.sort(ints2, sorter);
|
||||
System.out.println(join(ints2));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
import java.util.Comparator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IntConcat {
|
||||
public static Comparator<Integer> SORTER = (o1, o2) -> {
|
||||
String o1s = o1.toString();
|
||||
String o2s = o2.toString();
|
||||
|
||||
if (o1s.length() == o2s.length()) {
|
||||
return o2s.compareTo(o1s);
|
||||
}
|
||||
|
||||
int mlen = Math.max(o1s.length(), o2s.length());
|
||||
while (o1s.length() < mlen * 2) {
|
||||
o1s += o1s;
|
||||
}
|
||||
while (o2s.length() < mlen * 2) {
|
||||
o2s += o2s;
|
||||
}
|
||||
|
||||
return o2s.compareTo(o1s);
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
Stream<Integer> ints1 = Stream.of(
|
||||
1, 34, 3, 98, 9, 76, 45, 4
|
||||
);
|
||||
|
||||
System.out.println(ints1
|
||||
.parallel()
|
||||
.sorted(SORTER)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining())
|
||||
);
|
||||
|
||||
Stream<Integer> ints2 = Stream.of(
|
||||
54, 546, 548, 60
|
||||
);
|
||||
|
||||
System.out.println(ints2
|
||||
.parallel()
|
||||
.sorted(SORTER)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining())
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue