Learn some C + +

Source: Internet
Author: User

The description now has a lot of rectangles, each rectangle has a number, this number can be repeated, and 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;

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

#include <iostream>#include<string>#include<list>#include<algorithm>using namespacestd;classretangle{Private:        intA,b,c;  Public: Retangle (intA1,intB1,intC1): A (A1) {if(B1&GT;C1) {b=b1,c=C1;} Else{b=c1,c=B1;}        }; Friend Ostream&operator<< (Ostream & out,ConstRetangle &r) { out<<r.a<<" "<<r.b<<" "<<r.c<<Endl; } friendBOOL operator< (ConstRetangle &x,ConstRetangle &y) {if(X.A!=Y.A)returnX.a <y.a; if(x.b!=y.b)returnx.b <y.b; if(X.C!=Y.C)returnX.C <y.c; } friendBOOL operator==(ConstRetangle &x,ConstRetangle &y) {if(X.A==Y.A&AMP;&AMP;X.B==Y.B&AMP;&AMP;X.C==Y.C)return true; return false; }};intMain () {intN; CIN>>N;  while(n--)    {        intm; CIN>>m; List<retangle>St;  while(m--)        {            intA,b,c; CIN>>a>>b>>B;            St.push_back (Retangle (a,b,c));            St.sort ();        St.unique (); }         while(!St.empty ()) {cout<<St.front ();        St.pop_front (); }    }    return 0;}

Learn some C + +

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.