Pagini recente » Cod sursa (job #2574226) | Cod sursa (job #2127966) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2076471)
package com.company;
import java.io.*;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
private static PrintWriter printWriter;
private static Scan sc;
private static final String INPUT_FILE = "elmaj.in";
private static final String OUTPUT_FILE = "elmaj.out";
public static void main(String[] args) throws IOException {
sc = new Scan(INPUT_FILE);
printWriter = new PrintWriter(OUTPUT_FILE);
HashMap<Integer, Integer> hashTable = new HashMap<>();
int x, n;
n = sc.nextInt();
for (int i = 0; i < n; i++) {
x = sc.nextInt();
Integer valueForKeyX = hashTable.get(x);
if (valueForKeyX != null) {
hashTable.put(x, valueForKeyX + 1);
} else {
hashTable.put(x, 1);
}
}
boolean gasit = false;
Set<Integer> keys = hashTable.keySet();
for (Integer key : keys) {
int val = hashTable.get(key);
if (val > n/2) {
printWriter.printf("%d %d", key, val);
gasit = true;
break;
}
}
if (!gasit) {
printWriter.print(-1);
}
printWriter.close();
sc.close();
}
static class Scan {
static BufferedReader br;
static StringTokenizer st;
Scan(String file) throws IOException {
br = new BufferedReader(new FileReader(file));
}
String next() throws IOException {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
void close() throws IOException {
br.close();
}
}
}