fork(1) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct Point { int x,y; } Point;
  5. typedef int CMP(const void *a,const void *b);
  6.  
  7. int cmpA(const Point *a,const Point *b)
  8. {
  9. double A=hypot(a->x,a->y),B=hypot(b->x,b->y);
  10. return ((A)>(B))-((A)<(B));
  11. }
  12.  
  13. int cmpB(const Point *a,const Point *b)
  14. {
  15. return ((a->y)>(b->y))-((a->y)<(b->y));
  16. }
  17.  
  18. int cmpC(const Point *a,const Point *b)
  19. {
  20. return ((a->x)>(b->x))-((a->x)<(b->x));
  21. }
  22.  
  23. int main()
  24. {
  25. Point p[4]={{500,662},{921,660},{495,149},{839,421}};
  26. qsort(p+0,4,sizeof(Point),(CMP*)&cmpA);
  27. qsort(p+1,3,sizeof(Point),(CMP*)&cmpB);
  28. qsort(p+2,2,sizeof(Point),(CMP*)&cmpC);
  29. for(size_t i=0;i<4;++i) printf("(%d,%d)\n",p[i].x,p[i].y);
  30. return 0;
  31. }
Success #stdin #stdout 0s 2160KB
stdin
stdout
(495,149)
(839,421)
(500,662)
(921,660)