Pagini recente » Cod sursa (job #1913041) | Cod sursa (job #1373004) | Cod sursa (job #1765511) | Cod sursa (job #1001799) | Cod sursa (job #1686419)
#include <fstream>
#include <vector>
#define nmax 32749
using namespace std;
struct apar
{
long long x,nr;
};
vector <apar> viz[nmax];
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
long long n,i,j,maj,elmaj,x,mod;
f>>n;bool ok;maj=n/2;
apar nou;
for (i=1;i<=n;i++)
{
f>>x;mod=x%nmax;
for (j=0,ok=1;j<viz[mod].size()&&ok;j++)
{
if (viz[x][j].x==x)
{
ok=0;
viz[x][j].nr++;
if (viz[x][j].nr>maj)
maj=viz[x][j].nr,elmaj=x;
}
}
if (ok)
{
nou.x=x;nou.nr=1;
viz[mod].push_back(nou);
}
}
g<<elmaj<<' '<<maj<<'\n';
f.close();
g.close();
return 0;
}