Pagini recente » Cod sursa (job #1706576) | Profil chivur | Rating Ignotis (Ignotis) | Cod sursa (job #1760755) | Cod sursa (job #1294825)
#include <stdio.h>
FILE *fin, *fout;
int n, c = 1, *v, temp;
int main()
{
fin = fopen("elmaj.in", "r");
fout = fopen("elmaj.out", "w");
fscanf(fin, "%d", &n);
v = new int[n];
for(int i = 0; i< n; i++) fscanf(fin, "%d", &v[i]);
temp = v[0];
for(int i = 1; i< n; i++)
{
if(v[i] == temp) c++;
else c--;
if(c == 0)
{
temp = v[i];
c = 1;
}
}
c = 0;
for(int i = 0; i< n; i++) if(v[i] == temp) c++;
if(c >= n/2+1) fprintf(fout, "%d %d\n", temp, c);
else fprintf(fout, "-1\n");
fclose(fin);
fclose(fout);
return 0;
}