Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int n,x,y,a[101][101],i,j,v[50],k;
  7.  
  8. void citire()
  9. {
  10. ifstream f("listavecini.in");
  11. f>>n;
  12. while(f>>x>>y)
  13. {
  14. a[x][y]=a[y][x]=1;
  15. }
  16. f.close();
  17. }
  18.  
  19. void afisliste()
  20. {
  21. ofstream g("listavecini.out");
  22. for(i=1;i<=n;i++)
  23. {
  24. k=0;
  25. for(j=1;j<=n;j++)
  26. {
  27. if(a[i][j]==1)
  28. {
  29. k++;
  30. v[k]=j;
  31. }
  32. }
  33. g<<k<<" ";
  34. for(int f=1;f<=k;f++)
  35. for(int g=1;g<=k;g++)
  36. if(v[f]<v[g]) swap(v[f],v[g]);
  37. for(int f=1;f<=k;f++)
  38. {
  39. g<<v[f]<<" ";
  40. }
  41. g<<endl;
  42. }
  43. g.close();
  44. }
  45.  
  46. int main()
  47. {
  48. citire();
  49.  
  50. afisliste();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement