Pagini recente » Cod sursa (job #1306803) | Cod sursa (job #2457841) | Rating Tatar Dragos (Dragos123321) | Cod sursa (job #1875368) | Cod sursa (job #2384142)
import java.io.*;
import java.util.*;
public class data
{
public static void main(String []args) throws IOException
{
Scanner fr = null;
PrintWriter fw = null;
try
{
fr = new Scanner(new File("elmaj.in"));
fw = new PrintWriter("elmaj.out");
int n = Integer.parseInt(fr.nextLine());
int count = 1;
int last = fr.nextInt();
for(int i = 1; i < n; i++)
{
int t = fr.nextInt();
if(count == 0)
{
last = t;
count = 1;
}
else
{
if(t == last)
count++;
else
count--;
}
}
fr = new Scanner(new File("elmaj.in"));
fr.nextLine();
int occ = 0;
for(int i = 0; i < n; i++)
{
if(fr.nextInt() == last)
{
occ++;
}
}
if(occ >= (n / 2 + 1))
fw.printf("%d %d\n", last, occ);
else
fw.println(-1);
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
if(fr != null)
fr.close();
if(fw != null)
fw.close();
}
}
}