Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <climits>
- using namespace std;
- ifstream f("1.txt");
- int main()
- {
- int n,x,y,i,j,k=0,max,h,min1=INT_MAX,h1,m;
- f>>n;
- int a[n+1][n+1]={0};
- while(f>>x>>y)
- {
- a[x][y]=1;
- }
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[i][j]==1)
- k++;
- if(k<=min1)
- min1=k;
- cout<<"Nod "<<i<<" are gradul extern "<<k<<endl;
- }
- cout<<endl;
- max=-1;
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[j][i]==1)
- k++;
- if(k>=max)
- max=k;
- cout<<"Nod "<<i<<" are gradul intern "<<k<<endl;
- }
- cout<<endl;
- cout<<"Nodurile cu gradul intern maxim sunt: ";
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[j][i]==1)
- k++;
- if(k==max)
- cout<<i<<" ";
- }
- cout<<endl;
- cout<<"Nodurile cu gradul extern minim sunt: ";
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[i][j]==1)
- k++;
- if(k==min1)
- cout<<i<<" ";
- }
- cout<<endl;
- m=0;
- cout<<"Nod izolat este: "<<endl;
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[i][j]==1||a[j][i]==1)
- k=1,h=i;
- if(k==0)
- {
- cout<<h;
- m=1;
- }
- }
- if(m==0)
- cout<<"nu exista noduri izolate"<<endl;
- cout<<endl;
- m=0;
- cout<<"Noduri termin1ale sunt: "<<endl;
- for(i=1;i<=n;i++)
- {
- k=0;
- for(j=1;j<=n;j++)
- if(a[i][j]==1)
- k++;
- if(k==0)
- {
- cout<<i<<endl;
- m=1;
- }
- }
- if(m==0)
- cout<<"Nu sunt noduri termin1ale"<<endl;
- cout<<endl;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- cout<<endl;
- cout<<"DAti un nod ";
- cout<<endl;
- cin>>x;
- cout<<"Predecesorii lui "<<x<<" sunt: ";
- for(i=1;i<=n;i++)
- if(a[i][x]==1)
- cout<<i<<" ";
- cout<<endl;
- cout<<"Succesorii lui "<<x<<" sunt: ";
- for(i=1;i<=n;i++)
- if(a[x][i]==1)
- cout<<i<<" ";
- cout<<endl;
- cout<<"Alegeti operatie : "<<endl;
- cout<<"1-Afisare grad extern si intern noduri"<<endl;
- cout<<"2-Nodul de grad intern maxim"<<endl;
- cout<<"3-Nodul de grad extern minim"<<endl;
- cout<<"4-Nodurile izolate"<<endl;
- cout<<"5-Nodurile terminale"<<endl;
- cout<<"6-Predecesor si succesor"<<endl;
- cout<<"7-Iesire"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement