0% found this document useful (0 votes)
14 views

Prob Info

Uploaded by

Popular-Games
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Prob Info

Uploaded by

Popular-Games
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <fstream>

#include <cstring>
using namespace std;
ifstream fin("expresie.in");
ofstream fout("expresie.out");

char op[]="+-*/%";

struct nod
{
char info;
nod *st;
nod *dr;
};

void read(nod* &r)


{
char x;
fin>>x;
if(strchr(op,x)==NULL)
{
r=new nod;
r->info=x;
r->st=NULL;
r->dr=NULL;
}
else
{
r=new nod;
r->info=x;
read(r->st);
read(r->dr);
}
}

void SRD(nod *r)


{
if(strchr(op,r->info)) fout<<"(";
if(r->st!=NULL) SRD(r->st);
fout<<r->info;
if(r->dr!=NULL) SRD(r->dr);
if(strchr(op,r->info)) fout<<")";
}

void SDR(nod *r)


{
if(r->st!=NULL) SDR(r->st);
if(r->dr!=NULL) SDR(r->dr);
fout<<r->info;
}

int main()
{
nod *r;
read(r);
SRD(r);
fout<<endl;
SDR(r);
return 0;
}
#include<fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int n,t[100],a[100][100],p[100];

void citire()
{ fin>>n;
for(int i=1;i<=n;i++)
fin>>t[i];
}

void df(int s, int v, int niv)


{
a[s][v]=a[v][s]=niv;
p[v]=1;
for(int i=1;i<=n;i++)
if((t[i]==v || i==t[v]) && !p[i]) df(s,i,niv+1);
}

void afis()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) fout<<a[i][j]<<" ";
fout<<endl;
}
}

int main()
{
citire();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) p[j]=0;
df(i,i,0);
}
afis();
fin.close();
fout.close();
return 0;
}

sau cu Roy-Floyd

#include<fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

const int inf=1<<20;


int n,t[100],a[100][100];

void citire()
{ fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j) a[i][j]=inf;
for(int i=1;i<=n;i++)
{
fin>>t[i];
if(t[i]!=0) a[i][t[i]]=a[t[i]][i]=1;
}
}

void rf()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j && a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
}

void afis()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) fout<<a[i][j]<<" ";
fout<<endl;
}
}

int main()
{
citire();
rf();
afis();
fin.close();
fout.close();
return 0;
}

You might also like