Cod sursa(job #628773)

Utilizator sternvladStern Vlad sternvlad Data 2 noiembrie 2011 02:44:04
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <cstdlib>
#include <iostream>
#include <fstream>
int a[100][100],n,m,i,j;
struct nod
{ int informatia;
  nod *next;
};
nod *p,*u;
using namespace std;
void add(int a)
{
nod *q;
q=new nod;     
q->informatia=a;

if(p==NULL)
{
p=q;
u=q;
}
else
{
u->next=q;
u=q;    
} 
u->next=NULL;
}
void afis()
{
ofstream g ("sortaret.out");
nod *q;
q=p;
while(q!=NULL)
{
g<<q->informatia<<' ';              
q=q->next;             
}
}     
void citi ()
{ifstream f("sortaret.in");
int b,c;
f>>n>>m;
for (i=1;i<=m;i++)
{f>>b>>c;
a[b][c]=1;
}
}
int main(int argc, char *argv[])
{citi ();
int ok;
for (i=1;i<=n;i++) 
{ok=1;
for (j=1;j<=n;j++) if (a[i][j]==1) ok=0;
if (ok=1) add (i);
}
afis();

    
    return EXIT_SUCCESS;
}