Sima Guang, a historian of the Song Dynasty, has a famous "theory of virtue and talent" in his "general guide to the rule of capital": "it is because of this that all the talents and virtues are called saints, while both the talents and virtues are called fools, only when virtue prevails is called gentlemen, only when virtue prevails is called villains.". All the skills of taking people, not saints, gentlemen and it, with the villain, not if the fool
Now we will give the scores of a group of examinees. Please give the admission ranking according to Sima Guang's theory.
Input format:
Input the first line to give three positive integers, respectively: N (≤ 10.5), that is, the total number of candidates; l (≥ 60), that is, the lowest score line for admission, that is, candidates with a moral score and a talent score of not less than l are eligible for admission; H (< 100), that is the priority admission line - those with a moral score and a talent score of not less than this line are defined as "all the talents are virtuous", and such candidates are from the high according to the total score of the talents The candidates with lower scores but lower scores but lower scores in Germany are ranked as "deshengcai". They are also ranked according to the total scores, but they are ranked after the first category of candidates. The candidates with lower scores in Germany and talent, but not lower scores in Germany, are ranked as "both talented and dead" but still have "deshengcai". They are ranked according to the total scores, but they are ranked after the second category of candidates. The candidates with lower scores in L are also ranked according to the total scores But after the third category.
Then line N, each line gives the information of one examinee, including: the examination Permit No. is an 8-digit integer, and the examination Permit No. is an integer within the range [0, 100]. Numbers are separated by spaces.
Output format:
The first line of output first gives the number of candidates who have reached the lowest score line M, and then line M, each line outputs the information of one candidate according to the input format, and the candidates are sorted from high to low according to the rules described in the input. When more than one examinee in a certain category has the same total score, they shall be arranged in descending order of their moral scores; if their moral scores are also arranged in parallel, they shall be output in ascending order of the examination permit number.
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
- Analysis:
Sima cylinder divides people into these categories. Only when talent value and virtual value are up to standard (≥ L), can they participate in the classification. Otherwise, they are not recyclable waste
Qualified line: L \ excellent line: H
people | talent | virtue | note |
---|---|---|---|
sage | ≥ H | ≥ H | |
nobleman | < H | ≥ H | |
fool man | < H | < H | v ≥ t |
small man | ≥ L | ≥ L | Not meeting the above three |
-
Train of thought 1:
When inputting, all kinds of people are screened out by if ﹣ else, and the qualified people cnt is counted. These four kinds of people are stored by four vector s, and then output is sorted according to the requirements (1. The total score is not increased \ 2. The total score is the same, the virtual score is not increased \ 3. The same, the ID is increased) -
code1:
#include <stdio.h> #include <algorithm> #include <vector> using namespace std; int n, l, h; const int maxn = 100100; struct stu{ int id, virtue, talent; }s[maxn]; vector<stu> sta[3]; bool cmp(stu s1, stu s2){ if((s1.virtue + s1.talent) != (s2.virtue + s2.talent)) return (s1.virtue + s1.talent) > (s2.virtue + s2.talent); else if(s1.virtue != s2.virtue) return s1.virtue > s2.virtue; else return s1.id < s2.id; } int main(){ scanf("%d%d%d", &n, &l, &h); int cnt = n; for(int i = 0;i < n; ++i){ scanf("%d%d%d", &s[i].id, &s[i].virtue, &s[i].talent); if(s[i].virtue >= l && s[i].talent >= l){ if(s[i].virtue >= h && s[i].talent >= h){ sta[0].push_back(s[i]); }else if(s[i].virtue >= h && s[i].talent < h){ sta[1].push_back(s[i]); }else if(s[i].virtue < h && s[i].talent < h && s[i].virtue >= s[i].talent){ sta[2].push_back(s[i]); }else{ sta[3].push_back(s[i]); } }else{ cnt--; } } sort(sta[0].begin(), sta[0].end() , cmp); sort(sta[1].begin(), sta[1].end() , cmp); sort(sta[2].begin(), sta[2].end() , cmp); sort(sta[3].begin(), sta[3].end() , cmp); printf("%d\n", cnt); for(int i = 0; i < 4; ++i){ for(int j = 0; j < sta[i].size(); ++j){ printf("%d %d %d\n", sta[i][j].id, sta[i][j].virtue, sta[i][j].talent); } } return 0; }
-
Train of thought 2:
Define the category variable in the structure, and add this variable in sorting -
T2 code:
#include <bits/stdc++.h> using namespace std; struct Peo{ int id, v, t, total; Peo(int _id, int _v, int _t, int _total) : id(_id), v(_v), t(_t), total(_total){} }; vector<Peo> P[6]; bool cmp(Peo a, Peo b){ if(a.total != b.total) return a.total > b.total; else if(a.v != b.v) return a.v > b.v; else return a.id < b.id; } int main(){ int n, l, h, cnt = 0; scanf("%d %d %d", &n, &l, &h); for(int i = 0; i < n; ++i){ int id, v_score, t_score; scanf("%d %d %d", &id, &v_score, &t_score); Peo tmp = Peo(id, v_score, t_score, v_score+t_score); if(v_score >= l && t_score >= l){ if(v_score >= h && t_score >= h){ P[0].push_back(tmp); }else if(v_score >= h && t_score < h){ P[1].push_back(tmp); }else if(v_score < h && t_score < h && v_score >= t_score){ P[2].push_back(tmp); }else{ P[3].push_back(tmp); } cnt++; } } printf("%d\n", cnt); for(int i = 0; i < 4; ++i){ sort(P[i].begin(), P[i].end(), cmp); for(int j = 0; j < P[i].size(); ++j){ printf("%08d %d %d\n", P[i][j].id, P[i][j].v, P[i][j].t); } } return 0; }