Pagini recente » Cod sursa (job #1867390) | Cod sursa (job #1479366) | Cod sursa (job #708420) | Cod sursa (job #2065646) | Cod sursa (job #1167956)
#include <fstream>
#include <unordered_map>
#define in "elmaj.in"
#define out "elmaj.out"
std :: ifstream f(in);
std :: ofstream g(out);
class hashMajority {
protected :
std :: unordered_map < int , int> my_table;
public :
void Put(int x) {
if(my_table.find(x) != my_table.end()) {
std :: unordered_map < int , int > :: iterator got = my_table.find(x);
my_table.erase(got);
got->second += 1;
my_table.insert(*got);
}
else my_table.insert( {x, 1} );
}
void Solve(int N) {
bool ok = 0;
for(auto it : my_table)
if(it.second > N / 2) {
g << it.first << ' ' << it.second << '\n';
ok = 1;
break;
}
if(!ok) g << "-1\n";
}
};
int main() {
int N;
hashMajority obj;
f >> N;
for(int x, i = 1; i <= N; ++i) {
f >> x;
obj.Put(x);
}
obj.Solve(N);
}