publicclassMain{ publicstaticvoidmain(String[] args){ Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int[] array = newint[l]; for (int i = 0; i < array.length; i++) { array[i] = sc.nextInt(); } int r = sc.nextInt(); int[] array2 = newint[r]; for (int i = 0; i < array2.length; i++) { array2[i] = sc.nextInt(); }
List<Integer> res = new ArrayList<>(); int i = 0, j = 0; while (i != l && j != r) { if (array[i] == array2[j]) { res.add(array[i]); i++; j++; } elseif (array[i] > array2[j]) { i++; } else { j++; } } for (Integer re : res) { System.out.print(re + " "); } } }
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); List<List<Integer>> lists = new LinkedList<>(); for (int i = 0; i < m; i++) { int i1 = in.nextInt(); List<Integer> temp = new LinkedList<>(); for (int j = 0; j < i1; j++) { temp.add(in.nextInt()); } lists.add(temp); } Set<Integer> set = new HashSet<>(); set.add(0); while (true) { boolean flag = false; List<Integer> needToBeRemoved = null; for (List<Integer> l : lists) { for (Integer integer : l) { if (set.contains(integer)) { set.addAll(l); needToBeRemoved = l; flag = true; break; } } } lists.remove(needToBeRemoved); if (!flag) { break; } } System.out.println(set.size()); } }
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] array = newint[n]; List<Integer> list = new LinkedList<>(); for (int i = 0; i < array.length; i++) { array[i] = sc.nextInt(); list.add(array[i]); }
Collections.sort(list); int small = list.get(n / 2 - 1); int big = list.get(n / 2); for (int i = 0; i < n; i++) { if (array[i] <= small) { System.out.println(big); } else { System.out.println(small); } } } }