zoukankan      html  css  js  c++  java
  • 1015. 德才论 (25)

    宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子。才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人。不若得愚人。”


    现给出一批考生的德才分数,请依据司马光的理论给出录取排名。


    输入格式:


    输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60)。为录取最低分数线。即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”。此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H。可是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后。其它达到最低线L的考生也按总分排序,但排在第三类考生之后。


    随后N行。每行给出一位考生的信息,包含:准考证号、德分、才分,当中准考证号为8位整数,德才分为区间[0, 100]内的整数。

    数字间以空格分隔。


    输出格式:


    输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行依照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。

    当某类考生中有多人总分同样时,按其德分降序排列;若德分也并列。则按准考证号的升序输出。


    输入例子:
    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           

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Scanner;
    
    /**
     * @author jwang1 Success Factors
     */
    
    public class Main {
      public static void main(String[] args) {
        char[] ids = new char[10];
        ArrayList<Student> al1 = new ArrayList<Student>();
        ArrayList<Student> al2 = new ArrayList<Student>();
        ArrayList<Student> al3 = new ArrayList<Student>();
        ArrayList<Student> al4 = new ArrayList<Student>();
    
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int l = cin.nextInt();
        int h = cin.nextInt();
        for (int i = 0; i < n; i++) {
          Student s = new Student();
          s.setID(cin.next());
          s.setDe(cin.nextInt());
          s.setCai(cin.nextInt());
    
          if (s.getDe() >= l && s.getCai() >= l) {
            if (s.getDe() >= h && s.getCai() >= h) {
              al1.add(s);
            } else if (s.getDe() >= h && s.getCai() < h) {
              al2.add(s);
            } else if (s.getDe() < h && s.getCai() < h && s.getDe() >= s.getCai()) {
              al3.add(s);
            } else {
              al4.add(s);
            }
          }
        }
        
        Collections.sort(al1, new Sort());
        Collections.sort(al2, new Sort());
        Collections.sort(al3, new Sort());
        Collections.sort(al4, new Sort());
        
        System.out.println(al1.size() + al2.size() + al3.size() + al4.size());
        for (Student student : al1) {
          System.out.println(student.getID() + " " + student.getDe() + " "
              + student.getCai());
        }
        for (Student student : al2) {
          System.out.println(student.getID() + " " + student.getDe() + " "
              + student.getCai());
        }
        for (Student student : al3) {
          System.out.println(student.getID() + " " + student.getDe() + " "
              + student.getCai());
        }
        for (Student student : al4) {
          System.out.println(student.getID() + " " + student.getDe() + " "
              + student.getCai());
        }
      }
    }
    
    class Sort implements Comparator {
      public int compare(Object o1, Object o2) {
        Student s1 = (Student) o1;
        Student s2 = (Student) o2;
        if ((s1.getCai() + s1.getDe()) != (s2.getCai() + s2.getDe())) {
          return s2.getCai() + s2.getDe() - s1.getCai() - s1.getDe();
        } else if (s1.getDe() != s2.getDe()) {
          return s2.getDe() - s1.getDe();
        } else {
          return s1.getID().compareTo(s2.getID());
        }
      }
    }
    
    class Student {
      private String ID;
    
      public String getID() {
        return ID;
      }
    
      public void setID(String iD) {
        ID = iD;
      }
    
      public int getDe() {
        return De;
      }
    
      public void setDe(int de) {
        De = de;
      }
    
      public int getCai() {
        return Cai;
      }
    
      public void setCai(int cai) {
        Cai = cai;
      }
    
      private int De;
      private int Cai;
    }
    //本题仅仅能用C语言的输入输出。用C++的cin和cout会超时
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    
    using namespace std;
      
    typedef struct Student
    {
        string  ID;
    
        int  De;
        int Cai;
    }Student;
    
    inline bool compare(Student a,Student b)
    {
        if ((a.Cai+a.De)!=(b.Cai+b.De))
        return a.Cai+a.De>b.Cai+b.De;
        else if (a.De!=b.De)
        return a.De>b.De;
        else
        return a.ID<b.ID;
    }
    
    
    inline void print(Student s)
    {
    /*    cout<<s.ID<<" "<<s.De<<" "<<s.Cai<<endl;*/
        printf("%s %d %d
    ",s.ID.c_str(),s.De,s.Cai);
    }
    
    int main()
    {
         int N,L,H;
         char id[10];
         Student  S;
         string  ID;
         vector<Student>    vec1;
         vector<Student>    vec2;
         vector<Student>    vec3;
         vector<Student>    vec4;
    
        /* cin>>N>>L>>H;*/
         scanf("%d %d %d",&N,&L,&H);
    
         while(N--)
         {
            /*cin>>S.ID>>S.De>>S.Cai;*/
             scanf("%s%d%d",id,&S.De,&S.Cai);
             S.ID.assign(id);
            if (S.De>=L&&S.Cai>=L)
            {
                if (S.De>=H&&S.Cai>=H)
                    vec1.push_back(S);
                else
                if (S.De>=H&&S.Cai<H)
                    vec2.push_back(S);
                else
               if (S.De<H&&S.Cai<H&&S.De>=S.Cai)
                    vec3.push_back(S);
                else
                    vec4.push_back(S);    
            }
         }
         sort(vec1.begin(),vec1.end(),compare);
         sort(vec2.begin(),vec2.end(),compare);
         sort(vec3.begin(),vec3.end(),compare);
         sort(vec4.begin(),vec4.end(),compare);
    
        /* cout<<vec1.size()+vec2.size()+vec3.size()+vec4.size()<<endl;*/
         printf("%d
    ",vec1.size()+vec2.size()+vec3.size()+vec4.size());
    
         
         for_each(vec1.begin(),vec1.end(),print);
         for_each(vec2.begin(),vec2.end(),print);
         for_each(vec3.begin(),vec3.end(),print);
         for_each(vec4.begin(),vec4.end(),print);
        return 0;
    }


  • 相关阅读:
    调用https接口 报错:unable to find valid certification path
    POI生成Excel
    杂七杂八记录
    maven 打jar 包 pom.xml配置
    IDEA 全局修改项目版本
    Spring AOP的内部调用问题
    redis 中文乱码
    windows redis cluster 配置
    spring事物失效场景
    Mybatis常用示例
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7353424.html
Copyright © 2011-2022 走看看