Pagini recente » Cod sursa (job #315497) | Cod sursa (job #2702594) | Cod sursa (job #1228108) | Cod sursa (job #3264196) | Cod sursa (job #729002)
Cod sursa(job #729002)
#include <fstream>
#include <algorithm>
unsigned int v [1000000];
int main (void)
{
std::ifstream input("elmaj.in");
unsigned int n;
input >> n;
unsigned int *i(v),*limit(v + n);
unsigned int counter(0),elmaj;
do
{
input >> *i;
if (!counter)
{
elmaj = *i;
counter = 1;
}
else if (*i == elmaj)
++counter;
else
--counter;
++i;
}
while (i < limit);
input.close();
counter = std::count(v,limit,elmaj);
n >>= 1;
std::ofstream output("elmaj.out");
if (counter > n)
output << elmaj << ' ' << counter;
else
output << "-1";
output << '\n';
output.close();
return 0;
}