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
1
8
1 1 1
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
Sample output
1 1 1
1 2 1
1 2 2
2 1 1
2 2 1
Import Java.util.arraylist;import java.util.collections;import java.util.comparator;import java.util.HashSet; Import Java.util.list;import Java.util.scanner;import Java.util.set;public class Main {public static void main (string[] args) {Scanner sc = new Scanner (system.in); int n = integer.parseint (Sc.nextline ());//There are n test data while (n--> 0) {//Receive several moments Shape int count = Integer.parseint (Sc.nextline ());//count=8set<rect> set = new hashset<rect> (); for (int i = 0; I & Lt Count i++) {String rectstr = Sc.nextline ();//1 2 1string[] rects = Rectstr.split ("");//Calculate the length and width of the rectangle int length = Math.max (Integer . parseint (Rects[1]), Integer.parseint (rects[2]); int width = math.min (Integer.parseint (rects[1)), Integer.parseint ( RECTS[2])); Rect rect = new Rect (Integer.parseint (rects[0]), length, width); set.add (rect);} list<rect> list = new arraylist<rect> (set); Collections.sort (list, new Mycomparator ()); for (Rect rect:list) {System.out.println (rect.id + "+ rect.length +" "+ R ect.width);}}}}//define my own comparator class Mycomparator implements comparator<rect> {/** * Two rectangles, if the rectangle ID is different, sort in ascending order of rectangle if the rectangle ID is the same as the rectangle's long ascending order If the rectangle ID is the same, and the rectangle is long, sort by the width of the rectangle */@Overridepublic int compare (rect O1, rect O2) {if (o1.id! = o2.id) {return o1.id-o2.id;} E LSE if (O1.length! = o2.length) {return o1.length-o2.length;} else {//description ID and length same return o1.width-o2.width;}}} Class Rect {int id;int length;//rectangle long int width;//rectangle wide public Rect (int id, int length, int width) {this.id = Id;this.length = Length;this.width = width;} Here again equals method and hashcode, with ID and length and width to identify @overridepublic int hashcode () {final int prime = 31;int result = 1;result = P Rime * result + Id;result = Prime * result + Length;result = Prime * result + Width;return result;} @Overridepublic boolean equals (Object obj) {if (this = = obj) return true;if (obj = = null) return False;if (GetClass ()! = obj . GetClass ()) return false; Rect other = (rect) obj;if (id = other.id) return false;if (length! = other.length) return false;if (width = other.width) r EtUrn False;return true;}}
A sort of