Pagini recente » Diferente pentru utilizator/raresegay intre reviziile 15 si 1 | Profil tudorbuhnia | Cod sursa (job #426372) | Cod sursa (job #1486576) | Cod sursa (job #1649680)
#include <iostream>
#include <fstream>
using namespace std;
ofstream fout("elmaj.out");
unsigned const maxb = 8192;
unsigned ptr = maxb - 1;
char buf[maxb];
int getInt(ifstream &fin)
{
int rez = 0;
while(!(buf[ptr] >= '0' && buf[ptr] <= '9'))
{
if(++ptr >= maxb)
{
ptr = 0;
fin.read(buf, maxb);
}
}
while((buf[ptr] >= '0' && buf[ptr] <= '9'))
{
rez = rez * 10 + buf[ptr] - '0';
if(++ptr >= maxb)
{
ptr = 0;
fin.read(buf, maxb);
}
}
return rez;
}
int main()
{
int n, x, y, i, a;
ifstream fin("elmaj.in");
n = getInt(fin);
x = 0;
y = 0;
for(i = 1 ; i <= n ; i++)
{
a = getInt(fin);
if(y == 0)
{
x = a;
y = 1;
}
else if(x != a)
{
y--;
}
else
y++;
}
ifstream fin2("elmaj.in");
n = getInt(fin2);
y = 0;
for(i = 1 ; i <= n ; i++)
{
a = getInt(fin2);
if(a == x)
y++;
}
if(y >= n / 2 + 1)
{
fout << x << " " << y << "\n";
}
else
fout << "-1\n";
}