Advertisement
Guest User

sddfdf

a guest
Nov 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <climits>
  4.  
  5. using namespace std;
  6. ifstream f("1.txt");
  7. int main()
  8. {
  9. int n,x,y,i,j,k=0,max,h,min1=INT_MAX,h1,m;
  10. f>>n;
  11. int a[n+1][n+1]={0};
  12. while(f>>x>>y)
  13. {
  14. a[x][y]=1;
  15. }
  16. for(i=1;i<=n;i++)
  17. {
  18. k=0;
  19. for(j=1;j<=n;j++)
  20. if(a[i][j]==1)
  21. k++;
  22. if(k<=min1)
  23. min1=k;
  24. cout<<"Nod "<<i<<" are gradul extern "<<k<<endl;
  25. }
  26. cout<<endl;
  27. max=-1;
  28. for(i=1;i<=n;i++)
  29. {
  30. k=0;
  31. for(j=1;j<=n;j++)
  32. if(a[j][i]==1)
  33. k++;
  34. if(k>=max)
  35. max=k;
  36. cout<<"Nod "<<i<<" are gradul intern "<<k<<endl;
  37. }
  38. cout<<endl;
  39. cout<<"Nodurile cu gradul intern maxim sunt: ";
  40. for(i=1;i<=n;i++)
  41. {
  42. k=0;
  43. for(j=1;j<=n;j++)
  44. if(a[j][i]==1)
  45. k++;
  46. if(k==max)
  47. cout<<i<<" ";
  48. }
  49. cout<<endl;
  50. cout<<"Nodurile cu gradul extern minim sunt: ";
  51. for(i=1;i<=n;i++)
  52. {
  53. k=0;
  54. for(j=1;j<=n;j++)
  55. if(a[i][j]==1)
  56. k++;
  57. if(k==min1)
  58. cout<<i<<" ";
  59. }
  60. cout<<endl;
  61. m=0;
  62. cout<<"Nod izolat este: "<<endl;
  63. for(i=1;i<=n;i++)
  64. {
  65. k=0;
  66. for(j=1;j<=n;j++)
  67. if(a[i][j]==1||a[j][i]==1)
  68. k=1,h=i;
  69. if(k==0)
  70. {
  71. cout<<h;
  72. m=1;
  73. }
  74. }
  75.  
  76. if(m==0)
  77. cout<<"nu exista noduri izolate"<<endl;
  78. cout<<endl;
  79. m=0;
  80.  
  81. cout<<"Noduri termin1ale sunt: "<<endl;
  82. for(i=1;i<=n;i++)
  83. {
  84. k=0;
  85. for(j=1;j<=n;j++)
  86. if(a[i][j]==1)
  87. k++;
  88. if(k==0)
  89. {
  90. cout<<i<<endl;
  91. m=1;
  92. }
  93. }
  94. if(m==0)
  95. cout<<"Nu sunt noduri termin1ale"<<endl;
  96. cout<<endl;
  97. for(i=1;i<=n;i++)
  98. {
  99. for(j=1;j<=n;j++)
  100. cout<<a[i][j]<<" ";
  101. cout<<endl;
  102. }
  103. cout<<endl;
  104. cout<<"DAti un nod ";
  105. cout<<endl;
  106. cin>>x;
  107. cout<<"Predecesorii lui "<<x<<" sunt: ";
  108. for(i=1;i<=n;i++)
  109. if(a[i][x]==1)
  110. cout<<i<<" ";
  111. cout<<endl;
  112.  
  113. cout<<"Succesorii lui "<<x<<" sunt: ";
  114. for(i=1;i<=n;i++)
  115. if(a[x][i]==1)
  116. cout<<i<<" ";
  117. cout<<endl;
  118.  
  119.  
  120.  
  121. cout<<"Alegeti operatie : "<<endl;
  122. cout<<"1-Afisare grad extern si intern noduri"<<endl;
  123. cout<<"2-Nodul de grad intern maxim"<<endl;
  124. cout<<"3-Nodul de grad extern minim"<<endl;
  125. cout<<"4-Nodurile izolate"<<endl;
  126. cout<<"5-Nodurile terminale"<<endl;
  127. cout<<"6-Predecesor si succesor"<<endl;
  128. cout<<"7-Iesire"<<endl;
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement