Pagini recente » Cod sursa (job #2705437) | Cod sursa (job #597590) | Cod sursa (job #1226223) | Cod sursa (job #656278) | Cod sursa (job #634060)
Cod sursa(job #634060)
#include <cstdio>
#include <vector>
using namespace std;
#define MOD 666013
#define MAX 10005
vector <pair <int,int> > h[MOD];
int N,elem;
int pozitie=MAX-1;
char buff[MAX];
inline void cit (int &nr)
{
for (nr=0; buff[pozitie]<'0' || buff[pozitie]>'9'; )
if (++pozitie==MAX)
{
fread (buff,1,MAX,stdin);
pozitie=0;
}
for ( ; '0'<=buff[pozitie] && buff[pozitie]<='9'; )
{
nr=nr*10+buff[pozitie]-'0';
if (++pozitie==MAX)
{
fread (buff,1,MAX,stdin);
pozitie=0;
}
}
}
void insert (int nr,int poz)
{
for (vector <pair <int,int> > :: iterator it=h[poz].begin (); it!=h[poz].end (); ++it)
if (it->first==nr)
{
if (++it->second>(N>>1))
elem=it->first;
return ;
}
h[poz].push_back (make_pair (nr,1));
}
int find (int nr,int poz)
{
for (vector <pair <int,int> > :: iterator it=h[poz].begin (); it!=h[poz].end (); ++it)
if (it->first==nr)
return it->second;
return 0;
}
int main ()
{
freopen ("elmaj.in","r",stdin);
freopen ("elmaj.out","w",stdout);
scanf ("%d",&N);
for (int i=1; i<=N; ++i)
{
int nr; scanf ("%d",&nr);
insert (nr,nr%MOD);
}
if (elem)
printf ("%d %d",elem,find (elem,elem%MOD));
return 0;
}