Pagini recente » Cod sursa (job #1954366) | Cod sursa (job #1279685) | Cod sursa (job #321941) | Cod sursa (job #1910045) | Cod sursa (job #2384147)
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String []args) throws IOException
{
Scanner fr = null;
PrintWriter fw = null;
try
{
fr = new Scanner(new BufferedReader(new FileReader("C:\\Users\\arco\\Desktop\\code\\ads.txt")));
fw = new PrintWriter("C:\\Users\\arco\\Desktop\\code\\out.txt");
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("C:\\Users\\arco\\Desktop\\code\\ads.txt"));
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();
}
}
}