Pagini recente » Cod sursa (job #436766) | Cod sursa (job #1585749) | Cod sursa (job #932297) | Istoria paginii runda/rusinea_mea | Cod sursa (job #1209554)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream f("elmaj.in");
vector<int> v;
int votes = 0, candidate, n, k;
f >> k;
v.reserve(k);
while (k-- > 0)
{
f >> n;
v.push_back(n);
if (votes == 0)
{
candidate = n;
votes = 1;
}
else if (n == candidate)
votes++;
else
votes--;
}
votes = 0;
for (int i = 0; i < v.size(); i++)
if (v[i] == candidate)
votes++;
ofstream of("elmaj.out");
of << candidate << ' ' << votes << endl;
}