fork download
  1. //rlawnddnjs12 님의 소스를 이용하였습니다.
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. typedef struct time{
  5. int x;
  6. int y;
  7.  
  8. int cmp(const void *a,const void *b){
  9. time *x=(time *)a;
  10. time *y=(time *)b;
  11. if(x->y==y->y){
  12. return x->x > y->x;
  13. }
  14. else{
  15. return x->y > y->y;
  16. }
  17. }
  18.  
  19. int main(void){
  20. int n;
  21. scanf("%d",&n);
  22. time *t=(time *)calloc(n,sizeof(time));
  23. for(int i=0;i<n;i++)
  24. scanf("%d %d",&t[i].x,&t[i].y);
  25.  
  26. qsort(t,n,sizeof(time),cmp);
  27. for(int i=0;i<n;i++)
  28. printf("%d %d\n",t[i].x,t[i].y);
  29.  
  30. int cnt=1;
  31. int std_1=t[0].x;
  32. int std_2=t[0].y;
  33. for(int i=1;i<n;i++){
  34. if(std_2<=t[i].x){
  35. std_1=t[i].x;
  36. std_2=t[i].y;
  37. cnt++;
  38. }
  39. }
  40. printf("%d",cnt);
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5408KB
stdin
11
1 7
3 5
0 6
5 7
3 8
5 9
6 10
8 11
8 12
2 13
12 14
stdout
3 5
0 6
1 7
5 7
3 8
5 9
6 10
8 11
8 12
2 13
12 14
4