fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7.  
  8. public class Main {
  9.  
  10. static List c(final int[] f) {
  11. final LinkedList c = new LinkedList();
  12. for (final int i : f) {
  13. c.add(i);
  14. }
  15. for (; c.size() > 5;) {
  16. c.removeLastOccurrence(Collections.min(c));
  17. }
  18. return c;
  19. }
  20.  
  21. public static void main(final String[] a) {
  22. System.out.println(Arrays.toString(c(new int[]{ 0, 2, 5, 4, 0, 1, 0 }).toArray()));
  23. System.out.println(Arrays.toString(c(new int[]{ 2, 1, 1, 5, 3, 6 }).toArray()));
  24. System.out.println(Arrays.toString(c(new int[]{ 0, 4, 5 }).toArray()));
  25. System.out.println(Arrays.toString(c(new int[]{ 1, 1, 5, 1, 1, 5 }).toArray()));
  26. System.out.println(Arrays.toString(c(new int[]{ 0, 2, 0, 0, 0, 0, 0, 0 }).toArray()));
  27. System.out.println(Arrays.toString(c(new int[]{ 0, 0, 0, 0, 1, 0, 0, 0, 0 }).toArray()));
  28. System.out.println(Arrays.toString(
  29. c(new int[]{ 6, 3, 2, 0, 69, 22, 0, 37, 0, 2, 1, 0, 0, 0, 5, 0, 1, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2 })
  30. .toArray()));
  31. }
  32. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
[0, 2, 5, 4, 1]
[2, 1, 5, 3, 6]
[0, 4, 5]
[1, 1, 5, 1, 5]
[0, 2, 0, 0, 0]
[0, 0, 0, 0, 1]
[6, 69, 22, 37, 5]