Advertisement
NoHatred0

Atestat27

Feb 4th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <fstream.h>
  3. using namespace std;
  4.  
  5. ifstream f("atestat.in");
  6. ofstream g("atestat.out");
  7.  
  8. int n,a[100][100],v;
  9.  
  10. void citire()
  11. {
  12. int x,y;
  13. f>>n;
  14. while(!f.eof())
  15. {
  16. f>>x;f>>y;
  17. a[x][y]=1;
  18. a[y][x]=1;
  19. }
  20. }
  21. void afisare()
  22. {
  23. int i,j;
  24. for(i=1;i<=n;i++)
  25. {
  26. for(j=1;j<=n;j++)
  27. cout<<a[i][j]<<" ";
  28. cout<<endl;
  29. }
  30. }
  31. int grad(int x)
  32. {
  33. int i,s=0;
  34. for(i=1;i<=n;i++)
  35. s=s+a[x][i];
  36. return s;
  37. }
  38. void transformare()
  39. {
  40. int i,j;
  41. for(i=1;i<=n;i++)
  42. a[v][i]=1;
  43. for(j=1;j<=n;j++)
  44. a[j][v]=1;
  45. for(i=1;i<=n;i++)
  46. for(j=1;j<=n;j++)
  47. a[v][v]=0;
  48. }
  49. void afisare2()
  50. {
  51. int i,j;
  52. for(i=1;i<=n;i++)
  53. {
  54. for(j=1;j<=n;j++)
  55. g<<a[i][j]<<" ";
  56. g<<endl;
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. int i;
  63. citire();
  64. afisare();
  65. cout<<"Nodurile izolate sunt: "
  66. for(i=1;i<=n;i++)
  67. if(grad(i)==0)
  68. cout<<i<<" ";
  69. cout<<endl;
  70. cout<<"v=";cin>>v;
  71. transformare();
  72. afisare2();
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement