1183: Planar point sorting (I.) (Structural topics)

Source: Internet
Author: User
Tags printf

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


#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);
    for (i=0;i<n;i++) for
        if (stu[i].point<stu[j].point)
            T=stu[i] ;
     for (i=0;i<n;i++)
        if (i==n-1) printf ("(%d,%d)", stu[i].x,stu[i].y);
            printf ("(%d,%d)", stu[i].x,stu[i].y);

    return 0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.