Sort of planar points (I.) (Structural topics)

Source: Internet
Author: User

1183: Planar point sequencing (i) (structural features) time limit: 1 Sec Memory Limit: MB
Submit: 803 Solved: 555

Submitstatusweb Board 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 Input3 2 5 1 4 4 2Sample Output( 1,3) (1,4) (4,2) (2,5)HINT

SOURCE Exercise:
#include <iostream> #include <stdio.h> #include <algorithm>using namespace std;struct point{    int x;    int y;    int JLP;}; int CMP (point A,point b) {    return a.jlp<b.jlp;//ascending}int main () {    int n,i;    Point a[10];    while (scanf ("%d", &n)!=eof)    {for       (i=0;i<n;i++)       {           cin>>a[i].x>>a[i].y;           a[i].jlp=a[i].x*a[i].x+a[i].y*a[i].y;       }       Sort (a,a+n,cmp);       for (i=0;i<n;i++)       {           cout<< "(" <<a[i].x<< "," <<a[i].y<< ")" << "";       }    }    return 0;}

Sort of planar points (I.) (Structural topics)

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.