Advertisement
UberKill11

Vectras 2

Mar 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int a[101][101];
  5. int gri[101],gre[101];
  6. int n,m;
  7. int x[101], lg;
  8. void CitireMA()
  9. {
  10. int i,j;
  11. ifstream f("graf1.txt");
  12. f>>n;
  13. for(i=1;i<=n;i++)
  14. {
  15. for(j=1;j<=n;j++)
  16. f>>a[i][j];
  17. }
  18. f.close();
  19. }
  20. void CitireMuc()
  21. {
  22. int i,x,y;
  23. ifstream g("graf2.txt");
  24. g>>n;
  25. g>>m;
  26. for(i=1;i<=m;i++) //while (!g.eof()) while (f>>x>>y)
  27. {
  28. g>>x>>y;
  29. a[x][y]=1;
  30.  
  31. }
  32. g.close();
  33. }
  34. void VerifLantDrum()
  35. { int i,j,ok,s,d;
  36. cout <<endl;
  37. cout <<"Lungime lant/drum";
  38. cin >>lg;
  39. for(i=1;i<=lg;i++)
  40. cin >>x[i];
  41. ok=1;
  42. for(i=1;i<lg;i++)
  43. {
  44. s=x[i];d=x[i+1];
  45. // cout <<a[s][d]<<" ";
  46. if(a[s][d]==0 && a[d][s]==0)
  47. ok=0;
  48. }
  49. if(ok==1)
  50. {cout <<"E lant ";
  51. ok =1;
  52. for(i=1;i<lg;i++)
  53. for(j=i+1;j<=lg;j++)
  54. if (x[i]==x[j])
  55. ok=0;
  56. if(ok==1)
  57. cout <<"elem";
  58. else
  59. cout <<"Neelem,";
  60. }
  61. else
  62. cout <<"Nu e lant ";
  63.  
  64. ok=1;
  65. for(i=1;i<lg;i++)
  66. {
  67. s=x[i];d=x[i+1];
  68. if(a[s][d]==0 )
  69. ok=0;
  70. }
  71. if(ok==1)
  72. {
  73. cout <<"E drum ";
  74. if(x[lg]==x[1]) // sau a[x[n]][x[1]] ==1
  75. cout <<"circuit ";
  76. }
  77. else
  78. cout <<"Nu e drum ";
  79.  
  80. }
  81. void AfisareG()
  82. {
  83. int i,j;
  84. cout <<"Graf cu "<<n<<" noduri"<<endl;
  85. for(i=1;i<=n;i++)
  86. {
  87. for(j=1;j<=n;j++)
  88. {
  89. cout<<a[i][j]<<" ";
  90. }
  91. cout<<endl;
  92. }
  93. }
  94.  
  95. void GradeExterioare()
  96. {
  97. int i,j;
  98. cout <<"Grade exterioare " ;
  99. for(i=1;i<=n;i++)
  100. {
  101. gre[i]=0;cout <<"Multimea + este ";
  102. for(j=1;j<=n;j++)
  103. { gre[i]=gre[i]+a[i][j];
  104. if(a[i][j]==1)
  105. cout <<j<<" ";
  106. }
  107. cout<<" gradul ext:" <<gre[i]<<" ";
  108. cout <<endl;
  109. }
  110. }
  111. void GradeInterioare()
  112. {
  113. int i,j;
  114. cout <<"Grade interioare " ;
  115. for(j=1;j<=n;j++)
  116. {
  117. gri[j]=0; cout <<"Multimea - este ";
  118. for(i=1;i<=n;i++)
  119. { gri[j]=gri[j]+a[i][j];
  120. if(a[i][j]==1)
  121. cout <<i<<" ";
  122. }
  123. cout<<" gradul int:" <<gri[j]<<" ";
  124. cout <<endl;
  125. }
  126.  
  127. }
  128.  
  129.  
  130.  
  131. int main()
  132. {
  133. int i;
  134. CitireMA();
  135. AfisareG();
  136. CitireMuc();
  137. AfisareG();
  138. GradeExterioare();
  139. GradeInterioare();
  140. VerifLantDrum();
  141. cout<<endl;
  142.  
  143. return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement