Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class type {
- static int getMaxOfArray(int a[]) {
- int max = 0;
- for (int i = 0; i < a.length; i++) {
- if (a[i] > max)
- max = a[i];
- }
- return max;
- }
- public static void main(String args[]) throws NumberFormatException,
- IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- int t = Integer.parseInt(in.readLine());
- while (t-- > 0) {
- int a[], b[], result, max;
- int n = Integer.parseInt(in.readLine());
- /* define array b to update result */
- a = new int[n];
- String[] num = new String[n];
- num = in.readLine().split(" ");
- for (int i = 0; i < n; i++) {
- a[i] = Integer.parseInt(num[i]);
- }
- b = new int[getMaxOfArray(a)];
- /* update result */
- for (int i = 0; i < n; i++) {
- b[a[i]-1]++;
- }
- max = 0;
- result = 0;
- /* find max of array b and index of max*/
- for (int i = 0; i < b.length; i++) {
- if (b[i] == max) {
- if (i+1 < result)
- result = i+1;
- } else if (b[i] > max) {
- max = b[i];
- result = i+1;
- }
- }
- /*print result*/
- System.out.println(result + " " + b[result-1]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement