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 ;}