A sort time limit: theMs | Memory Limit:65535KB Difficulty:3
-
Describe
-
Now there are a lot of rectangles, each rectangle has a number, this number can be repeated, also know that the width and length of the rectangle, the number, length, width are all integers; now it's required to sort by a bit (the default collation is small to large);
1. Sort by number from small to large
2. For the numbers equal to the rectangle, according to the oblong long sort;
3. If the numbers and lengths are the same, sort by the width of the rectangle;
4. If the number, length, and width are the same, only one rectangle is reserved for sorting, the extra rectangles are removed, and the final sequence displays all rectangles in the specified format;
-
Input
-
The first line has an integer 0<n<10000, which indicates that there is an n set of test data next.
The first line of each group has an integer 0<m<1000, which indicates that there is a m rectangle;
The next M-line, each line has three numbers, the first number represents the number of rectangles,
The second and third numeric representations are long, the values are small, the representation is wide, equal
Description This is a square (data contract length width and number are less than 10000);
-
Output
-
Sequential output The number length of all eligible rectangles for each set of data
-
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
Idea: The use of the sort function
Code:
#include <stdio.h> #include <algorithm> using namespace std; struct node{int W,h,ans;} A[1000];bool CMP (node X,node y)//cmp function overrides {if (X.ans<y.ans) return true; if (x.ans==y.ans&&x.h<y.h) return true; if (X.ANS==Y.ANS&&X.H==Y.H&&X.W<Y.W) return true; return false;} int main () {int n,m,i; scanf ("%d", &n); while (n--) {scanf ("%d", &m); for (i=0;i<m;i++) {scanf ("%d%d%d", &A[I].ANS,&A[I].H,&A[I].W); if (A[I].H<A[I].W)///here should be careful to judge the long and wide Swap (A[I].H,A[I].W); } sort (a,a+m,cmp); printf ("%d%d%d\n", A[0].ANS,A[0].H,A[0].W); for (i=1;i<m;i++)//control output, the same will not output the {if (a[i].ans==a[i-1].ans&&a [I].H==A[I-1].H&&A[I].W==A[I-1].W] continue; printf ("%d%d%d\n ", A[I].ANS,A[I].H,A[I].W); }} return 0;}
Nyoj 81 kinds of sorting (sort use)