Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Spectacol
  5. {
  6. int nr;
  7. int inc, fin;
  8. } *v;
  9.  
  10.  
  11. int cmp ( const void *p, const void *q)
  12. {
  13. struct Spectacol *m = p;
  14. struct Spectacol *n = q;
  15.  
  16. if ((m->fin)<(n->fin)) return -1;
  17. return 1;
  18. }
  19.  
  20. int main()
  21. {
  22. int n, i, j=0;
  23. int *sol;
  24.  
  25. scanf ( "%d", &n);
  26. v = ( struct Spectacol * ) malloc ( n*sizeof(struct Spectacol) ) ;
  27. sol = ( int * ) malloc ( n* sizeof (int) );
  28. for ( i=0; i<n; i++)
  29. scanf ("%d %d %d", &v[i].nr, &v[i].inc, &v[i].fin);
  30.  
  31. qsort (v, n, sizeof(struct Spectacol), cmp);
  32.  
  33.  
  34. sol[0]=v[0].nr;
  35. int indice=v[0].fin;
  36.  
  37. for(i=1;i<n;i++)
  38. if (v[i].inc >= indice )
  39. {
  40. indice = v[i].fin;
  41. sol[++j]=v[i].nr;
  42. }
  43.  
  44. for (i=0;i<=j;i++)
  45. printf ( "%d ", sol[i]);
  46.  
  47.  
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment