Pagini recente » Cod sursa (job #2270753) | Cod sursa (job #966326) | Cod sursa (job #151219) | Cod sursa (job #2441867) | Cod sursa (job #1995831)
#include <fstream>
#define NMAX 1000000
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int v[NMAX],elmaj,cnt,i,n;
void _elmaj()
{
elmaj = v[1];
cnt = 0;
for( i = 1; i <= n; i ++ )
{
if( elmaj == v[i] )
cnt++;
else
cnt--;
if ( cnt < 0 )
{
elmaj = v[i];
cnt = 1;
}
}
cnt = 0;
for ( i = 1; i <= n; i ++)
if ( v[i] == elmaj )
cnt++;
if( cnt >= n / 2 + 1 )
g << elmaj << " " << cnt;
else
g << "-1";
}
int main()
{
f >> n;
for (i = 1; i<=n; i++)
f >> v[i];
_elmaj();
return 0;
}