Untitled
unknown
plain_text
4 years ago
1.4 kB
48
Indexable
import java.util.Scanner; public class bai_4 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int sobotest = scanner.nextInt(); for (int i = 1; i <= sobotest; i++) { int n = scanner.nextInt(); int count; int[] a = new int[n]; int[] b = new int[n]; for (int j = 0; j < n; j++) { a[j] = scanner.nextInt(); b[j] = -1; } for (int j = 0; j < n; j++) { count = 1; for (int k = j + 1; k < n; k++) { if (b[k] != 0 && a[j] == a[k]) { count++; b[k] = 0; } } if (b[j] != 0) { b[j] = count; } } int max = b[0]; for (int j = 0; j < n; j++) { if (b[j] > max) { max = b[j]; } for (j = 0; j < n; j++) { if (max > (n / 2) && b[j] == max) { System.out.println(a[j]); //} else { // System.out.println("NO"); } } } } } }
Editor is loading...