# PAT BASIC LEVEL 1015. 德才论 (25)

2017-01-13 19:14:10来源:CSDN作者:J_C_Weaton人点击

# 1015. 德才论 (25)

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

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

``#include<stdio.h>#include<algorithm>struct student {    int sno;    int morality;    int talent;    int total;    int rank;};bool compare(student a, student b) {    if(a.rank != b.rank)        return a.rank < b.rank;    else if(a.total != b.total)        return a.total > b.total;    else if(a.morality != b.morality)        return a.morality > b.morality;    return a.sno < b.sno;}int get_rank(student& s, int h, int l) {    if(s.morality >= h && s.talent >= h)        return 0;    if(s.morality < l || s.talent < l)        return 4;    if(s.morality >= h)        return 1;    if(s.talent >= l && s.morality >= s.talent)        return 2;    return 3;}int main() {    int n, l, h;    scanf("%d %d %d", &n, &l, &h);    student stus[n];    int c = 0;    for(int i = 0;i < n;i ++) {        student st;        scanf("%d %d %d",&st.sno,&st.morality,&st.talent);        st.rank = get_rank(st, h, l);        st.total = st.morality + st.talent;        if(st.rank < 4) {            stus[c++] = st;        }    }    printf("%d/n", c);    std::sort(stus, stus+c, compare);    for(int i = 0;i < c;i++)        printf("%d %d %d/n", stus[i].sno, stus[i].morality, stus[i].talent);}``

PS.