Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<fstream>
  2. #include<iostream>
  3. using namespace std;
  4. int a[100][100],n;
  5. char nume[100][100];
  6. int grad (int x)
  7. { int i,s=0;
  8. for(i=1;i<=n;i++)
  9. if(a[i][x]==1) s++;
  10. return s;
  11. }
  12. void citire()
  13. { ifstream f("prietenie.in");
  14. int i,j;
  15. f>>n;
  16. for(i=1;i<=n;i++)
  17. f>>nume[i];
  18. while(f>>i>>j)
  19. a[i][j]=a[j][i]=1;
  20. }
  21. int main ()
  22. { citire();
  23. int maxi=0,i,j;
  24. for(i=1;i<=n;i++)
  25. if(grad(i)>maxi) maxi=grad(i);
  26. for(i=1;i<=n;i++)
  27. if(grad(i)==maxi)
  28. { cout<<nume[i]<<":"<<endl;
  29. for(j=1;j<=n;j++)
  30. if(a[i][j]==1) cout<<" "<<nume[j]<<" cu alti "<<grad(j)-1<<" prieteni "<<endl;
  31. }
  32.  
  33. }
  34.  
  35.  
  36. 7
  37. Ion
  38. Petru
  39. Mara
  40. Clara
  41. Ana
  42. Dan
  43. George
  44. 1 3
  45. 1 5
  46. 3 4
  47. 3 6
  48. 4 6
  49. 4 7
  50. 2 6
  51. 6 7
  52. 5 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement