ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PAT甲级 1062 Talent and Virtue 排序+模拟

2019-09-01 11:36:27  阅读:302  来源: 互联网

标签:Talent temp grade 1062 high int Virtue total cmp


在这里插入图片描述
在这里插入图片描述

代码如下:

//排序
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

struct people{
    int id;
    int v_grade;//美德成绩
    int t_grade;//智力成绩
    int total;//总成绩
};

vector<people> sage;//圣人
vector<people> nobleman;//君子
vector<people> smallman;//小人
vector<people> foolman;//愚人
int n;
int ans=0;//有效人数
int low,high;

bool cmp(people a,people b){
    if(a.total>b.total){
        return true;
    }else if(a.total==b.total){
        if(a.v_grade>b.v_grade){
            return true;
        }else if(a.v_grade==b.v_grade){
            return a.id<b.id;
        }
    }
    return false;
}

int main(){
    cin>>n>>low>>high;
    for(int i=0;i<n;i++){
        people temp;
        cin>>temp.id>>temp.v_grade>>temp.t_grade;
        temp.total=temp.v_grade+temp.t_grade;
        int v=temp.v_grade,t=temp.t_grade;
        if(v<low||t<low){
            continue;
        }else if(v>=high&&t>=high){
            ans++;
            sage.push_back(temp);
        }else if(v>=high&&t<high){
            ans++;
            nobleman.push_back(temp);
        }else if(v<high&&t<high&&v>=t){
            ans++;
            foolman.push_back(temp);
        }else{
            ans++;
            smallman.push_back(temp);
        }
    }

    sort(sage.begin(),sage.end(),cmp);
    sort(nobleman.begin(),nobleman.end(),cmp);
    sort(foolman.begin(),foolman.end(),cmp);
    sort(smallman.begin(),smallman.end(),cmp);

    cout<<ans<<endl;
    for(int i=0;i<sage.size();i++){
        cout<<sage[i].id<<' '<<sage[i].v_grade<<' '<<sage[i].t_grade<<endl;
    }
    for(int i=0;i<nobleman.size();i++){
        cout<<nobleman[i].id<<' '<<nobleman[i].v_grade<<' '<<nobleman[i].t_grade<<endl;
    }
    for(int i=0;i<foolman.size();i++){
        cout<<foolman[i].id<<' '<<foolman[i].v_grade<<' '<<foolman[i].t_grade<<endl;
    }
    for(int i=0;i<smallman.size();i++){
        cout<<smallman[i].id<<' '<<smallman[i].v_grade<<' '<<smallman[i].t_grade<<endl;
    }
    return 0;
}

标签:Talent,temp,grade,1062,high,int,Virtue,total,cmp
来源: https://blog.csdn.net/weixin_44123362/article/details/100181501

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有