zoukankan      html  css  js  c++  java
  • 一个关于组织学员学习技术的笔试题--求讨论

    题目如下:

    JAVA编程实现如下需求:

    2018年05期培训班组织技术学习与分享,有如下技术可供选择:

    VirtualBox

    Vagrant

    WebSocket

    JSONP

    Redis

    MongoDB

    Cassandra

    RabbitMQ

    ActiveMQ

    Kafka

    Lucene

    Solr

    ElasticSearch

    Hadoop

    HDFS

    HIVE

    PIG

    Mahout

    HBase

    Spark

    Guava

    Protobuf

    Avro

    Thrift

    Motan

    Docker

    DynamoDB

    Scala

    Groovy

    SpringBoot

    学员每人选择其中两项进行学习,并在学习会以Demo的形式分享给其他同事。学员们的意向如下:

    吕鹏飞 ElasticSearch Redis

    丁虎 Redis SpringBoot

    梁秀斗 Hadoop HDFS

    李文鹏 Docker Kafka

    苗桓飞 Lucene Solr

    佘昊 Solr Redis

    杜世阳 ActiveMQ Hadoop

    刘翩 SpringBoot ActiveMQ

    史建智 Docker Lucene

    王帅 Cassandra Spark

    张昌昌 SpringBoot MongoDB

    王腾飞 SpringBoot Spark

    杨小平 WebSocket RabbitMQ

    请编写程序为学员安排最终的技术学习清单,要求:

    * 如果一项技术只有一个学员选择,则直接为该学员指定该技术

    * 如果一项技术有多个学员选择,则在选择了该项技术的学员中随机指定一位学习该技术

    * 如果一个学员被指定的技术不足两项,则在未被指定的技术中随机指定一项或两项给该学员,以凑足两项但不能多于两项。

    * 每个学员被指定的技术不能重复

    * 需要输出最终的技术指定清单

    * 需要输出未被指定给学员的技术清单

    我的思路及代码:

    package com.zy.zhy;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    import java.util.Random;

    import org.junit.Test;


    public class First {
            //所有技术
            private static List<String> courceList = new ArrayList<String>();
            static{
                    courceList.add("VirtualBox");courceList.add("Vagrant");
                    courceList.add("WebSocket");courceList.add("JSONP");
                    courceList.add("Redis");courceList.add("MongoDB");
                    courceList.add("Cassandra");courceList.add("RabbitMQ");
                    courceList.add("ActiveMQ");courceList.add("Kafka");
                    courceList.add("Solr");courceList.add("ElasticSearch");
                    courceList.add("Hadoop");courceList.add("HDFS");
                    courceList.add("HIVE");courceList.add("PIG");
                    courceList.add("Mahout");courceList.add("HBase");
                    courceList.add("Spark");courceList.add("Guava");
                    courceList.add("Protobuf");courceList.add("Avro");
                    courceList.add("Thrift");courceList.add("Motan");
                    courceList.add("Docker");courceList.add("DynamoDB");
                    courceList.add("Scala");courceList.add("Groovy");
                    courceList.add("SpringBoot");courceList.add("Lucene");
            };
            //所有学员
            private static Map<String,String[]> map = new HashMap<String,String[]>();
            static{
                    map.put("吕鹏飞", new String[]{"ElasticSearch","Redis"});
                    map.put("丁虎", new String[]{"Redis","SpringBoot"});
                    map.put("梁秀斗", new String[]{"Hadoop","HDFS"});
                    map.put("李文鹏", new String[]{"Docker","Kafka"});
                    map.put("苗桓飞", new String[]{"Lucene","Solr"});
                    map.put("佘昊", new String[]{"Solr","Redis"});
                    map.put("杜世阳", new String[]{"ActiveMQ","Hadoop"});
                    map.put("刘翩", new String[]{"SpringBoot","ActiveMQ"});
                    map.put("史建智", new String[]{"Docker","Lucene"});
                    map.put("王帅", new String[]{"Cassandra","Spark"});
                    map.put("张昌昌", new String[]{"SpringBoot","MongoDB"});
                    map.put("王腾飞", new String[]{"SpringBoot","Spark"});
                    map.put("杨小平", new String[]{"WebSocket","RabbitMQ"});
            }       
    privatestaticMap<String,List> okMap =newHashMap<String,List>();       
    static{                okMap
    .put("吕鹏飞",null);                okMap
    .put("丁虎",null);                okMap
    .put("梁秀斗",null);                okMap
    .put("李文鹏",null);                okMap
    .put("苗桓飞",null);                okMap
    .put("佘昊",null);                okMap
    .put("杜世阳",null);                okMap
    .put("刘翩",null);                okMap
    .put("史建智",null);                okMap
    .put("王帅",null);                okMap
    .put("张昌昌",null);                okMap
    .put("王腾飞",null);                okMap
    .put("杨小平",null);       
    }       
    @Test       
    publicvoid test(){                method1
    ();                method2
    ();               
    for(Entry<String,List> stu : okMap.entrySet()){                       
    int count = methodB(stu.getKey());                       
    if(count==1){                               
    String course = getCourse();                               
    List<String> list=stu.getValue();                               
    if(list==null){                                        list
    =newArrayList<>();                               
    }                                list
    .add(course);                                okMap
    .put(stu.getKey(),list);                       
    }elseif(count==0){                               
    for(int i=0;i<2;i++){                                       
    String course = getCourse();                                       
    List<String> list=stu.getValue();                                       
    if(list==null){                                                list
    =newArrayList<>();                                       
    }                                        list
    .add(course);                                        okMap
    .put(stu.getKey(),list);                               
    }                       
    }               
    }               
    System.out.println(okMap);       
    }       
    //第一次遍历课程然后排除掉一部分课程(两个以上学员选择的)       
    publicvoid method1(){               
    Iterator<String> it = courceList.iterator();               
    while(it.hasNext()){                       
    List list = methodA(it.next());                       
    String cource = it.next();                       
    if(list.size()==2){                                list
    .remove(0);                               
    String name = getName(list.toArray());                               
    ArrayList<String> okList =newArrayList<String>();                                okList
    .add(cource);                                okMap
    .put(name, okList);                                it
    .remove();                       
    }               
    }       
    }       
    //第二次遍历课程然后再排除掉一部分课程(只有一个学员选择的)       
    publicvoid method2(){               
    Iterator<String> it = courceList.iterator();               
    while(it.hasNext()){                       
    List list = methodA(it.next());                       
    String cource = it.next();                       
    if(list.size()>2){                                list
    .remove(0);                               
    String name = getName(list.toArray());                               
    ArrayList<String> okList =newArrayList<String>();                                okList
    .add(cource);                                okMap
    .put(name, okList);                                it
    .remove();                       
    }               
    }       
    }       
    //查询某个学员选了几项技术       
    publicint methodB(String name){               
    List list = okMap.get(name);               
    if(list==null){                       
    return0;               
    }               
    return list.size();       
    }       
    //判断某项技术有哪些学员选择       
    publicList<String> methodA(String str){               
    List<String> list =newArrayList<String>();                list
    .add(str);               
    for(Entry<String,String[]> stu : map.entrySet()){                       
    for(Stringstring: stu.getValue()){                               
    if(str.equals(string)){                                        list
    .add(stu.getKey());                               
    }                       
    }               
    }               
    return list;       
    }       
    //随机返回一门技术       
    publicString  getCourse(){               
    //随机指定技术               
    Random random =newRandom();               
    String[] s=newString[courceList.size()];               
    int i=0;               
    for(Objectobject: courceList){                        s
    [i]=(String)object;                        i
    ++;               
    }               
    String course = s[random.nextInt(courceList.size())];                courceList
    .remove(course);               
    return course;       
    }       
    //随机返回一个学员姓名       
    publicString  getName(Object... code){               
    //随机指定学员               
    Random random =newRandom();               
    String[] s=newString[code.length];               
    int i=0;               
    for(Objectobject: code){                        s
    [i]=(String)object;                        i
    ++;               
    }               
    //System.out.println(code[random.nextInt(code.length)]);               
    return s[random.nextInt(code.length)];       
    }
    }

    输出结果:

    {佘昊=[WebSocket, MongoDB], 杨小平=[JSONP, Docker], 丁虎=[Motan, Thrift], 张昌昌=[Protobuf, Redis], 刘翩=[Lucene, Avro], 梁秀斗=[HDFS, Spark], 苗桓飞=[ElasticSearch, Cassandra], 王腾飞=[Guava, PIG], 史建智=[HBase, Mahout], 李文鹏=[DynamoDB, VirtualBox], 杜世阳=[Kafka, Scala], 王帅=[RabbitMQ, Solr], 吕鹏飞=[Hadoop, Groovy]}

    如有疑问,欢迎留言讨论。
  • 相关阅读:
    mybatis中的动态语句中多条件or如何书写
    安装kibana的docker版
    安装elasticsearch的docker版
    git回滚push过的代码
    java中支付宝支付
    05 docker镜像删除
    远程仓库的搭建
    本地git工作流
    创建本地仓库
    git安装
  • 原文地址:https://www.cnblogs.com/zhhy/p/9492630.html
Copyright © 2011-2022 走看看