每位应聘者先按其第一志愿录取(从高分到低分依次对);当不能按其第一志愿录取时,便将他的成绩扣去5分后,重新排队,并按其第二志愿考虑录取。
    为了严格控制录取人数,公司规定,如果出现分数相同的情况,优先录取编号靠前的人员。
    各事业部录取不设最低分数线,招聘至额满为止,或已对全部应聘者都作了录取处理。
    程序需要输出各事业部实际招聘的应聘人员,每个事业部的被录取者需要是有序队列(按被录取者成绩从高到低)。
    
    所有输入、输出采用文本文件的形式,并都放在 c:\test 目录下。并且,文件记录从第一行开始,即没有表头行。    输入文件信息
    1)计划招聘人数的信息,包含了所有参加本次招聘的事业部名称,及各自计划招聘的人数。文件名称:plan.txt,
    每行记录为一个事业部的录取计划人数信息,内容为:
      事业部名称,计划招聘人数
    2)应聘者成绩及所申请的事业部开发岗位信息。文件名称:source.txt,每行为一个应聘者的信息,内容为:
      人员编号,成绩,事业部名称1,事业部名称2    输出文件要求:
    1)输入格式为事业部名称与录用人员编号列表。文件名称:result.txt,每行为一个事业部的录取情况,内容为:
      事业部名称:人员编号1,人员编号2,人员编号3
    2)为了方便结果的校验,结果请按事业部名称升序输出。
plan.txt内容如下
a部门,3
b部门,2
c部门,4source.txt内容如下
1,86,a部门,c部门
2,20,a部门,c部门
3,43,a部门,b部门
4,92,b部门,a部门
5,54,c部门,a部门result.txt内容如下
a部门,4,22,13
b部门,19,1,
c部门,14,25,23,8,5,以上文件为假设例子,具体实现以题目要求为准。

解决方案 »

  1.   

    哎。 做了1个小时15分钟。 哎呀 还以为只要半个小时呢。package bumen;import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;public class Luqu {
    public static final String PLAN = "D:/123/input/plan.txt";    //3个文件的地址
    public static final String SOURCE = "D:/123/input/source.txt";   
    public static final String RESULT = "D:/123/output/result.txt";   
    public static void main(String[] args) throws Exception {
    /*
     * 把plan.txt的内容读进来
     */
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(PLAN))));
    String line = null;
    List<Plan> pList = new ArrayList<Plan>();
    while((line = br.readLine()) != null){
    Plan p = new Plan();
    p.dpName = line.split(",")[0];
    p.count = Integer.parseInt(line.split(",")[1]);
    pList.add(p);
    }
    /*
     * 把source.txt的内容读进来
     */
    BufferedReader br1 = new BufferedReader(new InputStreamReader(new FileInputStream(new File(SOURCE))));
    List<Source> sList = new ArrayList<Source>();
    while((line = br1.readLine()) != null){
    Source s = new Source();
    s.id = Integer.parseInt(line.split(",")[0]);
    s.score = Integer.parseInt(line.split(",")[1]);
    s.first = line.split(",")[2];
    s.second = line.split(",")[3];
    sList.add(s);
    }
    Collections.sort(sList); //排序
    List<Source> sList2 = new ArrayList<Source>();   //第一轮未录取
    //进行第一轮录取
    for(Source s : sList){
    for(Plan p : pList){
    if(s.first.equals(p.dpName)){//找到对应的部门
    if(!p.enroll(s)){  //如果没被录取,加入未录取列表
    sList2.add(s);
    }
    break;
    }
    }
    }
    //进行第二轮录取
    for(Source s : sList2){
    for(Plan p : pList){
    if(s.second.equals(p.dpName)){//找到对应的部门
    p.enroll(s);
    break;
    }
    }
    }
    //输出到文件
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(RESULT)));
    for(Plan p : pList){
    System.out.println(p);
    out.println(p);
    }
    out.close();
    }
    }class Plan{
    String dpName;
    int count;
    List<Integer> enrollList = new ArrayList<Integer>(); //录取名单
    public boolean enroll(Source s){
    if(count != 0){
    enrollList.add(s.id);
    count --;
    return true;
    }
    return false;
    }
    public String toString(){
    StringBuilder sb = new StringBuilder();
    for(Integer i : enrollList){
    sb.append(","+i);
    }
    return dpName+sb.toString();
    }

    }class Source implements  Comparable<Source> {
    int id;
    int score;
    String first;
    String second;
    //排序,先按照分数,如果分数相同 按ID
    public int compareTo(Source o) {
    return (score - o.score) != 0 ? (o.score - score) : (id - o.id);
    }
    }
      

  2.   

    我也说一下逻辑吧:
    1.读写txt就不说了(得到部门list和职员list),我是按照部门list循环执行的,每一次先找出第一志愿和第二志愿选报这个部门的,当然第二志愿的set成绩的时候减5.
    2.然后就是排序,并取出要求的人数,然后把职员list已经被选入员工remove
    3.循环下一个部门