Description
There are n points on the plane, and the coordinates are integers. Sort all points by the distance from the origin of the coordinates (0,0). You can write your own sort functions, or you can sort them with qsort library functions. Input
The input has two lines, the first line is an integer n (1<=n<=10), followed by n rows, and a pair of integers per line (one point for each pair of integers). Output
Outputs all the points after sorting, in the format (U,V), with a space after each point. The test data guarantees that the distance from each point to the origin is different. Sample Input 3 2 5 1 4 4 2 sample Output (1,3) (1,4) (4,2) (2,5) HINT
Source
#include <stdio.h>
#include <stdlib.h>
typedef struct STUDENT
{
int x;
int y;
int point;
} STU;
int main ()
{
int n,i,j;
scanf ("%d", &n);
STU stu[20],t;
for (i=0;i<n;i++)
{
scanf ("%d%d", &stu[i].x,&stu[i].y);
stu[i].point=stu[i].x*stu[i].x+stu[i].y*stu[i].y;
}
for (i=0;i<n;i++) for
(j=0;j<n;j++)
{
if (stu[i].point<stu[j].point)
{
T=stu[i] ;
STU[I]=STU[J];
stu[j]=t;
}
}
for (i=0;i<n;i++)
{
if (i==n-1) printf ("(%d,%d)", stu[i].x,stu[i].y);
else
printf ("(%d,%d)", stu[i].x,stu[i].y);
}
return 0;
}