Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. int a[1001][1001],n,m;
  5.  
  6. ofstream out("date.out");
  7.  
  8. void construiremat(int a[][1001],int&n,int&m,int&h)
  9. {
  10. int x,y,i,j;
  11. ifstream in("date.in");
  12. in>>n>>m;
  13. for(i=1; i<=m; i++)
  14. {
  15. in>>x>>y;
  16. a[x][y]=1;
  17. }
  18. for(i=1; i<=n; i++)
  19. {
  20. for(j=1; j<=n; j++)
  21. {
  22. a[0][i]+=a[j][i];
  23. a[i][0]+=a[i][j];
  24. }
  25. }
  26. in>>h;
  27. in.close();
  28. }
  29.  
  30. void succesor(int x, int n)
  31. {
  32. out<<'\n';
  33. int i;
  34. out<<"succesori "<<x<<": ";
  35. for(i=1; i<=n; i++)
  36. {
  37. if(a[x][i]==1)
  38. out<<i<<" ";
  39. }
  40. }
  41.  
  42. void predecesor(int x, int n)
  43. {
  44. out<<'\n';
  45. int i;
  46. out<<"predecesori "<<x<<": ";
  47. for(i=1; i<=n; i++)
  48. {
  49. if(a[i][x]==1)
  50. out<<i<<" ";
  51. }
  52. }
  53.  
  54. void uplus(int x, int n)
  55. {
  56. out<<'\n';
  57. int i;
  58. out<<"Arcele care ies din "<<x<<": ";
  59. for(i=1; i<=n; i++)
  60. {
  61. if(a[x][i]==1)
  62. out<<"("<<x<<","<<i<<") ";
  63. }
  64. }
  65.  
  66. void uminus(int x, int n)
  67. {
  68. out<<'\n';
  69. int i;
  70. out<<"Arcele care intra din "<<x<<": ";
  71. for(i=1; i<=n; i++)
  72. {
  73. if(a[i][x]==1)
  74. out<<"("<<i<<","<<x<<") ";
  75. }
  76. }
  77.  
  78. int main()
  79. {
  80. int n,m,x,i,j;
  81. construiremat(a,n,m,x);
  82. out<<"nodurile in care gradul intern este egal cu gradul extern:";
  83. for(i=1; i<=n; i++)
  84. {
  85. if(a[0][i]==a[i][0])
  86. {
  87. out<<i<<" ";
  88. }
  89. }
  90. out<<'\n';
  91. succesor(x,n);
  92. predecesor(x,n);
  93. uplus(x,n);
  94. uminus(x,n);
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement