Pagini recente » Cod sursa (job #2359010) | Cod sursa (job #2535233) | Cod sursa (job #1233986) | Cod sursa (job #1652699) | Cod sursa (job #157818)
Cod sursa(job #157818)
#include<fstream.h>
struct nod{int info;
nod *urm;
};
int n,m; nod *lista[1000];
void adaug(nod *&p,int x)
{
nod *q=new nod();
q->info=x;
q->urm=p;
p=q;
}
void citire()
{ifstream f("sortaret.in");
f>>n>>m;
int x1,x2;
while(f>>x1>>x2)
adaug(lista[x1],x2);
f.close();
}
int are_tata(int varf)
{nod *p;
for(int i=1;i<=n;i++)
{p=lista[i];
while(p)
{ if(p->info==varf)
return 1;
p=p->urm;
}
}
return 0;
}
int main()
{int N,i,j,t[5000]={0};
citire();
N=n;
ofstream g("sortaret.out");
while(N>=1)
{
for(i=1;i<=n;i++)
if(t[i]!=-1)
t[i]=are_tata(i);
for(i=1;i<=n;i++)
if(t[i]==0)
{g<<i<<" ";
t[i]=-1;
lista[i]=NULL;
N--;
}
}
g.close();
return 0;
}