POJ C + + programming Problem # #: Sorting and classification of crowds

Source: Internet
Author: User

Programming Question # #: the sort and classification of crowds

Source: Peking University Online Program evaluation system POJ (Coursera statement: The exercises completed on POJ will not count to the final results of Coursera. )

Total time limit: 1000ms memory limit: 1024kB

Describe

The population is sorted and categorized according to the information entered.

#include <iostream> #include <set> #include <iterator> #include <algorithm>using namespace std ;//Add your code here int main () {        int t;        CIN >> T;        Set<a*,comp> CT;        while (T--) {                int n;                CIN >> N;                Ct.clear ();                for (int i = 0;i < n; ++i) {                        char c; int k;                        Cin >> c >> K;                        if (c = = ' A ')                                Ct.insert (New A (k));                        else                                Ct.insert (new B (k));                }                For_each (Ct.begin (), Ct.end (), Print);                cout << "* * *" << Endl;        }}
Input

The first line is the integer t, which indicates the total T-group data. T < 20

For each group of data:

The first line is an integer n, which indicates a total of n rows below. 0 < n < 100

Each of the following lines represents a single person. Each line starts with a letter, represents the category that the person belongs to, and then follows an integer that represents the age. The letter will only be ' A ' or ' B '. Integer range 0 to 100. Data is guaranteed to be of different ages.

Output

For each set of input data, these people are exported by age from small to large. Each person outputs the category before outputting the age. Add a line to the end of each group of data "* * *"

Sample input
24A 3B 4 A 5B 63A 4 a 3 a 2

Sample output
A 3B 4 a 5B 6****a 2A 3 a 4****
1#include <iostream>2#include <Set>3#include <iterator>4#include <algorithm>5 using namespacestd;6 //Add your code here7 classA {8  Public:9     intAge ;Ten     strings; OneAintA): Age (a), S ("A"){} AAintAstringstr): Age (a), S (str) {} - }; -  the classB: PublicA { -  Public: -Bintb): A (b,"B") {} - }; +  - structComp { +     BOOL operator()(ConstA * A1,ConstA * A2)Const { A         returnA1->age < a2->Age ; at     } - }; -  - voidPrint (ConstAa) { -cout<<a->s<<" "<<a->age <<Endl; - } in  - intMain () to { +  -     intT; theCIN >>T; *     Set<A*,Comp>CT; $      while(T-- ) {Panax Notoginseng         intN; -CIN >>N; the ct.clear (); +          for(inti =0; i < n; ++i) { A             CharCintK; theCIN >> C >>K; +  -             if(c = ='A') $Ct.insert (NewA (k)); $             Else -Ct.insert (NewB (k)); -         } the For_each (Ct.begin (), Ct.end (), Print); -cout <<"****"<<Endl;Wuyi     } the}

POJ C + + programming Problem # #: Sorting and classification of crowds

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.