Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Spectacol
- {
- int nr;
- int inc, fin;
- } *v;
- int cmp ( const void *p, const void *q)
- {
- struct Spectacol *m = p;
- struct Spectacol *n = q;
- if ((m->fin)<(n->fin)) return -1;
- return 1;
- }
- int main()
- {
- int n, i, j=0;
- int *sol;
- scanf ( "%d", &n);
- v = ( struct Spectacol * ) malloc ( n*sizeof(struct Spectacol) ) ;
- sol = ( int * ) malloc ( n* sizeof (int) );
- for ( i=0; i<n; i++)
- scanf ("%d %d %d", &v[i].nr, &v[i].inc, &v[i].fin);
- qsort (v, n, sizeof(struct Spectacol), cmp);
- sol[0]=v[0].nr;
- int indice=v[0].fin;
- for(i=1;i<n;i++)
- if (v[i].inc >= indice )
- {
- indice = v[i].fin;
- sol[++j]=v[i].nr;
- }
- for (i=0;i<=j;i++)
- printf ( "%d ", sol[i]);
- return 0;
- }
Add Comment
Please, Sign In to add comment