Pagini recente » Cod sursa (job #1258023) | Monitorul de evaluare | Cod sursa (job #1253934) | Cod sursa (job #557408) | Cod sursa (job #1623651)
#include <fstream>
#include <set>
using namespace std;
struct INT {
int x, p;
};
set<INT> s;
bool operator < (const INT A, const INT B) {
return A.x < B.x;
}
int main()
{
ifstream f("algsort.in");
ofstream g("algsort.out");
int n, x; INT aux; f >> n;
for(int i = 1; i <= n; i ++) {
f >> x; aux.x = x;
set<INT>::iterator it = s.find(aux);
aux = *it;
if(aux.p != 0) {
s.erase(it);
aux.p ++;
}
else aux.x = x, aux.p = 1;
s.insert(aux);
}
for(set<INT>::iterator it = s.begin(); it != s.end(); it ++) {
INT aux = *it;
for(int j = 1; j <= aux.p; j ++) g << aux.x << " ";
}
g << "\n";
return 0;
}