Pagini recente » Cod sursa (job #1082347) | Cod sursa (job #2190704) | Profil monsieurlazar | Cod sursa (job #486215) | Cod sursa (job #2973738)
#include <fstream>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
struct nod
{
int info;
nod* urm;
};
void adaugareFinal(nod *&h, int x)
{
if (h == NULL)
{
h = new nod;
h->info = x;
h->urm = NULL;
} else
{
nod* p = h;
while (p->urm)
p = p->urm;
nod* nou = new nod;
nou->info = x;
nou->urm = NULL;
p->urm = nou;
}
}
int main()
{
int n, m;
fin >> n >> m;
int v[100] = {};
nod* w[100] = {};
for (int i = 0; i < m; i++)
{
int x, y;
fin >> x >> y;
adaugareFinal(w[x], y);
v[y]++;
}
for (int i = 0; i < n; i++)
{
int j;
for (j = 1; j <= n; j++)
if (v[j] == 0)
break;
fout << j << " ";
v[j] = -1;
nod* p = w[j];
while (p)
{
v[p->info]--;
p = p->urm;
}
}
}