On C + + Sima

Source: Internet
Author: User

/*
Problem:
The Song Dynasty historian Sima Guang in "the Capital Governance Tong Jian" has a well-known "the Moral Only Theory": "is therefore only then the virtuous all says the sage, only then the German and the Dead is the Fool, the German wins only then says the gentleman, only then wins the moral

Villain. Whoever takes the technique of the person, Gou not saints, gentleman and with it, with the villain, not if the fool. ”



Now give a number of candidates of the German score, please according to Sima Guang theory to give admission rankings.


Input Description:

Enter the 1th line to give 3 positive integers: N (<=105), that is, the total number of candidates, L (>=60), for the admission of the minimum score, that is, the German and want $ are not less than L candidates are eligible

is considered to be admitted, H (<100), for the priority line--the German and want $ are not below this line is defined as "only de full", such candidates by virtue of the total score from high to low ranking; want $

But the German division to the line of a class of candidates belonging to the "Desheng", but also according to the overall ranking, but ranked in the first category after the candidates, Germany want $ are lower than H, but no less than want $ candidates belong to "only Germany and

"But there are" Desheng ", ranked by total, but ranked after the second category of candidates, and other people who reached the minimum line L were ranked by total, but ranked after the third category of candidates.


Then n lines, each line gives a candidate's information, including: The ticket number, German points, want $, where the ticket number is a 8-bit integer, Germany is divided into the interval [0, 100] integer. The numbers are separated by a space.

Output Description:

Output line 1th first gives the number of candidates to reach the minimum fraction m, followed by M, each line in the input format to output a candidate's information, candidates according to the rules indicated in the input from high to low sort. When there are more than one type of candidate

The total score is at the same time, in descending order according to their German points;


Input Example:

14 60 80

10000001 64 90

10000002 90 60

10000011 85 80

10000003 85 80

10000004 80 85

10000005 82 77

10000006 83 76

10000007 90 78

10000008 75 79

10000009 59 90

10000010 88 45

10000012 80 100

10000013 90 99

10000014 66 60


Output Example:

12

10000013 90 99

10000012 80 100

10000003 85 80

10000011 85 80

10000004 80 85

10000007 90 78

10000006 83 76

10000005 82 77

10000002 90 60

10000014 66 60

10000008 75 79

10000001 64 90

How to solve the problem: construct the structure first, then use the vector to store 4 types of results, using sort from large to small (we need to write a CMP method to compare to the big to the small sort)

*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace Std;
Building structures
typedef struct{
int id;//No.
int d;//Moral Education Division
int c;//can be divided into
}stu;
Sort sorted by
BOOL CMP (const STU &a,const stu &b)
{
if ((A.C+A.D) = = (B.C+B.D)) {//score same
Moral education is divided into different
if (A.D==B.D) return a.id<b.id;//sorted by school number from small to large
else return a.d>b.d;//otherwise by moral education divided from big to small sort
}else return (A.C+A.D) > (B.C+B.D);//Sort by total score from large to small
}
Output function
void print (const stu &v) {
cout<<v.id<< "" <<v.d<< "" <<v.c<<endl;
}
int main () {
int n,l,h,countt=0;
Vector<stu> Fir,sec,thi,fou;
CIN >> n>>l>>h;
while (n--) {
Stu temp;//defines a variable
CIN >>temp.id>>temp.d>>temp.c;
if (temp.d>=l&&temp.c>=l) {//eligible to participate in the rankings
countt++;
if (temp.d>=h&&temp.c>=h) fir.push_back (temp);
else if (temp.d>=h&&temp.celse if (temp.delse Fou.push_back (temp);
}
}
Sort
Sort (Fir.begin (), Fir.end (), CMP);
Sort (Sec.begin (), Sec.end (), CMP);
Sort (Thi.begin (), Thi.end (), CMP);
Sort (Fou.begin (), Fou.end (), CMP);
cout<<countt<<endl;
Traverse
For_each (Fir.begin (), Fir.end (), print);
For_each (Sec.begin (), Sec.end (), print);
For_each (Thi.begin (), Thi.end (), print);
For_each (Fou.begin (), Fou.end (), print);
return 0;
}

On C + + Sima

Related Article

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.