Cod sursa(job #1623651)

Utilizator serbanSlincu Serban serban Data 1 martie 2016 20:49:30
Problema Sortare prin comparare Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#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;
}