fork download
  1. import java.util.*;
  2. class OdaiUniqSortRev {
  3. public static int[] uniq(int[] a) {
  4. return Arrays.stream(a).distinct().toArray();
  5. }
  6. public static int[] sort(int[] a) {
  7. int[] b = Arrays.copyOf(a, a.length);
  8. Arrays.sort(b);
  9. return b;
  10. }
  11. public static int[] reverse(int[] a) {
  12. int[] b = Arrays.copyOf(a, a.length);
  13. for (int i = 0, j = b.length - 1; i < j; i++, j--) {
  14. int t = b[i];b[i] = b[j];b[j] = t;
  15. }
  16. return b;
  17. }
  18. private static void p(int[] a) {
  19. System.out.println(Arrays.toString(a));
  20. }
  21. public static void main(String[] args) {
  22. int[] a = {3, 1, 4, 1, 5};
  23. p(reverse(sort(uniq(a))));
  24. p(Arrays.stream(a).boxed().distinct().sorted(Comparator.reverseOrder()).mapToInt(Integer::intValue).toArray());
  25. }
  26. }
  27.  
Success #stdin #stdout 0.08s 34368KB
stdin
Standard input is empty
stdout
[5, 4, 3, 1]
[5, 4, 3, 1]