Sort by nyoj8 (simple sort) and nyoj8

Source: Internet
Author: User

Sort by nyoj8 (simple sort) and nyoj8
A sort time limit: 3000 MS | memory limit: 65535 KB difficulty: 3

Description
There are many rectangles. Each rectangle has a number, which can be repeated. We also know that the width and length of the rectangle are integers; sort by the following method (the default sorting rules are from small to large );

1. sort by number from small to large

2. For rectangles with equal numbers, they are sorted by the length of the rectangles;

3. If the numbers and lengths are the same, they are sorted by the width of the rectangle;

4. If the numbers, lengths, and widths are the same, only one rectangle is retained for sorting and redundant rectangles are deleted. Finally, all the rectangles are displayed in the order in the specified format;
Input
The first row has an integer of 0 <n <10000, indicating that there are n groups of test data;
The first row of each group has an integer of 0 <m <1000, indicating that there are m rectangles;
In the next m row, each row has three numbers. The first number indicates the number of the rectangle,

The length of the second and third values is large, and the width of the smaller values is equal.
This is a square (the agreed length and width of the data are less than 10000 );
Output
Sequentially output the numbers and lengths of all rectangle matching the conditions of each data set.
Sample Input
181 1 11 1 11 1 21 2 11 2 22 1 12 1 22 2 1
Sample output
1 1 11 2 11 2 22 1 12 2 1
Source

Typical questions

# Include <stdio. h ># include <algorithm> using namespace std; struct st {int xh; int c, k;} data [1010]; int cmp (st a, st B) // sorting key! {If (a. xh! = B. xh) return a. xh <B. xh; else if (a. c! = B. c) return a. c <B. c; else if (a. k! = B. k) return. k <B. k;} int main () {int test, I, n, t; scanf ("% d", & test); while (test --) {scanf ("% d", & n); for (I = 0; I <n; I ++) {scanf ("% d ", & data [I]. xh, & data [I]. c, & data [I]. k); // pay attention to the length and width. If (data [I]. c <data [I]. k) {t = data [I]. c; data [I]. c = data [I]. k; data [I]. k = t ;}} sort (data, data + n, cmp); for (I = 0; I <n; I ++) {if (! (Data [I]. xh = data [I + 1]. xh & data [I]. c = data [I + 1]. c & data [I]. k = data [I + 1]. k) printf ("% d \ n", data [I]. xh, data [I]. c, data [I]. k) ;}} 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.