1062 Talent and Virtue (25 分)(排序)

1062 Talent and Virtue (25 分)

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.

Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.

Input Specification:

Each input file contains one test case. Each case first gives 3 positive integers in a line: N (≤10​5​​ ), the total number of people to be ranked; L (≥60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are considered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".

Then N lines follow, each gives the information of a person in the format:

ID_Number Virtue_Grade Talent_Grade

where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.

Output Specification:

The first line of output must give M (≤N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
    int id,vir,tal,total;
};
bool cmp(node a,node b){
    if(a.total!=b.total) return a.total>b.total;
    else{
        if(a.vir!=b.vir) return a.vir>b.vir;
        else return a.id<b.id;
    }
}
int main(){
    int n,L,H;
    cin>>n>>L>>H;
    vector<node> v[4]; 
    int cnt=0;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(b<L||c<L) continue;
        cnt++;
        if(b>=H && c>=H) v[0].push_back(node{a,b,c,b+c});
        else if(c<H && b>=H ) v[1].push_back(node{a,b,c,b+c});
        else if(c<H && b<H && b>=c) v[2].push_back(node{a,b,c,b+c});
        else v[3].push_back(node{a,b,c,b+c});
    }
    
    for(int i=0;i<4;i++) sort(v[i].begin(),v[i].end(),cmp);
    printf("%d\n",cnt);
    for(int i=0;i<4;i++){
        for(int j=0;j<v[i].size();j++){
            printf("%08d %d %d\n",v[i][j].id,v[i][j].vir,v[i][j].tal);
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 8,079评论 0赞 10
  • 我们的文化是提倡勤俭节约,反对铺张浪费的。这一点我以前从未怀疑,但是现在这个观念有那么一点点松动。 第一次产生怀疑...
    薛定饿着猫阅读 909评论 0赞 0
  • “谈钱伤感情,不过我们之间没什么感情,还是谈钱比较直接…”这是周星驰说过的一句话。 人们总是把钱和利益等同起来,只...
    月夜梦婵阅读 494评论 0赞 0
  • 人生,就是一场盛大的遇见。若你懂得,就请珍惜…… 梦里你喊醒了我,我发个动态也也许吵醒你...
    江湖救急啊阅读 182评论 0赞 0

友情链接更多精彩内容